@@ -391,236 +391,4 @@ We'll need Traefik Hub with API Management!
391391
392392## Step 3: Manage an API with Traefik Hub API Management
393393
394- First, we enable API Management on Traefik Traefik Hub using the same Helm chart:
395-
396- ``` shell
397- helm upgrade traefik -n traefik --wait \
398- --version v34.4.1 \
399- --reuse-values \
400- --set hub.apimanagement.enabled=true \
401- traefik/traefik
402- ```
403-
404- Traefik Hub API Management is 100% compatible with Traefik Proxy v3 and Traefik Hub API Gateway.
405-
406- The dashboard is still reachable on http://dashboard.docker.localhost/
407-
408- ![ Local Traefik Hub Dashboard] ( ./src/images/hub-dashboard.png )
409-
410- And also confirm that the API is still secured using an API Key:
411-
412- ``` shell
413- # This call is not authorized => 401
414- curl -i http://walkthrough.docker.localhost/api-key/weather
415- # This call with the token is allowed => 200
416- curl -s -H " Authorization: Bearer $API_KEY " http://walkthrough.docker.localhost/api-key/weather | jq
417- ```
418-
419- Now, let's try to manage it with Traefik Hub using ` API ` and ` APIAccess ` resources:
420-
421- ``` yaml :src/manifests/walkthrough/api.yaml -s 1 -e 23
422- ---
423- apiVersion : hub.traefik.io/v1alpha1
424- kind : API
425- metadata :
426- name : walkthrough-weather-api
427- namespace : apps
428- spec :
429- openApiSpec :
430- path : /openapi.yaml
431- override :
432- servers :
433- - url : http://api.walkthrough.docker.localhost
434-
435- ---
436- apiVersion : hub.traefik.io/v1alpha1
437- kind : APIAccess
438- metadata :
439- name : walkthrough-weather-api
440- namespace : apps
441- spec :
442- apis :
443- - name : walkthrough-weather-api
444- everyone : true
445- ` ` `
446-
447- We'll need to reference this API in the ` IngressRoute` with an annotation:
448-
449- ` ` ` yaml :src/manifests/walkthrough/api.yaml -s 25 -e 41
450- ---
451- apiVersion: traefik.io/v1alpha1
452- kind: IngressRoute
453- metadata:
454- name: walkthrough-weather-api
455- namespace: apps
456- annotations:
457- hub.traefik.io/api: walkthrough-weather-api # <=== Link to the API using its name
458- spec:
459- entryPoints:
460- - web
461- routes:
462- - match: Host(` api.walkthrough.docker.localhost`) && PathPrefix(`/weather`)
463- kind : Rule
464- services :
465- - name : weather-app
466- port : 3000
467- ` ` `
468-
469- :information_source: We've also removed the API Key authentication middleware, as we'll use Traefik Hub's built-in identity provider for user and credential management. The API is still secured, as we'll see it shortly.
470-
471- Let's apply it:
472-
473- ` ` ` shell
474- kubectl apply -f src/manifests/walkthrough/api.yaml
475- ```
476-
477- It will create ` API ` , ` APIAccess ` and link ` IngressRoute ` to this API.
478-
479- ``` shell
480- api.hub.traefik.io/walkthrough-weather-api created
481- apiaccess.hub.traefik.io/walkthrough-weather-api created
482- ingressroute.traefik.io/walkthrough-weather-api created
483- ```
484-
485- Now, we can confirm this API is not publicly exposed:
486-
487- ``` shell
488- curl -i http://api.walkthrough.docker.localhost/weather
489- ```
490-
491- It returns the expected 401 Unauthorized HTTP code:
492-
493- ``` shell
494- HTTP/1.1 401 Unauthorized
495- Date: Mon, 06 May 2024 12:09:56 GMT
496- Content-Length: 0
497- ```
498-
499- ## Step 4: Create a user for this API
500-
501- Users are created in the [ Traefik Hub Online Dashboard] ( https://hub.traefik.io/users ) :
502-
503- ![ Create user admin] ( ./api-management/1-getting-started/images/create-user-admin.png )
504-
505- ## Step 5: Deploy the API Portal
506-
507- The user created previously will connect to an API Portal to generate an API key, so let's deploy the API Portal!
508-
509- ``` yaml :src/manifests/walkthrough/api-portal.yaml
510- ---
511- apiVersion : hub.traefik.io/v1alpha1
512- kind : APIPortal
513- metadata :
514- name : walkthrough-apiportal
515- namespace : apps
516- spec :
517- title : API Portal
518- description : " Apps Developer Portal"
519- trustedUrls :
520- - http://api.walkthrough.docker.localhost
521-
522- ---
523- apiVersion : networking.k8s.io/v1
524- kind : Ingress
525- metadata :
526- name : walkthrough-apiportal
527- namespace : traefik
528- annotations :
529- # This annotation link this Ingress to the API Portal using <name>@<namespace> format.
530- hub.traefik.io/api-portal : walkthrough-apiportal@apps
531- spec :
532- rules :
533- - host : api.walkthrough.docker.localhost
534- http :
535- paths :
536- - path : /
537- pathType : Prefix
538- backend :
539- service :
540- name : apiportal
541- port :
542- number : 9903
543- ` ` `
544-
545- :information_source: This API Portal is routed with the internal _ClusterIP_ ` Service` named apiportal.
546-
547- ` ` ` shell
548- kubectl apply -f src/manifests/walkthrough/api-portal.yaml
549- sleep 60
550- ` ` `
551-
552- ` ` ` shell
553- apiportal.hub.traefik.io/walkthrough-apiportal created
554- ingress.networking.k8s.io/walkthrough-apiportal created
555- ` ` `
556-
557- The API Portal should be reachable on http://api.walkthrough.docker.localhost
558-
559- We log in with the admin user.
560-
561- 
562-
563- And create a token for this user :
564-
565- 
566-
567- ` ` ` shell
568- export ADMIN_TOKEN="XXX"
569- ` ` `
570-
571- Request the API with this token : :tada:
572-
573- ` ` ` shell
574- curl -s -H "Authorization: Bearer $ADMIN_TOKEN" http://api.walkthrough.docker.localhost/weather | jq
575- ` ` `
576-
577- ` ` ` json
578- [
579- {"city":"GopherTown","id":"0","weather":"Cloudy"},
580- {"city":"City of Gophers","id":"1","weather":"Sunny"},
581- {"city":"GopherRocks","id":"2","weather":"Cloudy"}
582- ]
583- ` ` `
584-
585- :information_source : If it fails with 401, wait one minute and try again. The token needs to be sync before it can be accepted by Traefik Hub.
586-
587- We can see the API available in the `apps` namespace in the portal. We advise every API to come with an OpenAPI specification (OAS) :
588-
589- 
590-
591- However, it's still possible not setting an OAS, but it severely hurts getting started with API consumption.
592-
593- This time, we won't specify any OAS in the API _CRD_ :
594-
595- ` ` ` yaml :src/manifests/walkthrough/forecast.yaml -s 1 -e 7
596- ---
597- apiVersion: hub.traefik.io/v1alpha1
598- kind: API
599- metadata:
600- name: walkthrough-weather-api-forecast
601- namespace: apps
602- spec: {}
603- ` ` `
604-
605- The other resources are built on the same model, as we can see in [the complete file](https://github.com/traefik/hub/blob/main/api-management/1-getting-started/manifests/forecast.yaml). Let's apply it :
606-
607- ` ` ` shell
608- kubectl apply -f src/manifests/weather-app-forecast.yaml
609- kubectl apply -f src/manifests/walkthrough/forecast.yaml
610- ` ` `
611-
612- ` ` ` shell
613- api.hub.traefik.io/walkthrough-weather-api-forecast created
614- apiaccess.hub.traefik.io/walkthrough-weather-api-forecast created
615- ingressroute.traefik.io/walkthrough-weather-api-forecast created
616- ` ` `
617-
618- Request the API with the token :
619-
620- ` ` ` shell
621- curl -H "Authorization: Bearer $ADMIN_TOKEN" http://api.walkthrough.docker.localhost/forecast/weather
622- ` ` `
623-
624- And that's it! This time, we have documentation built from the OpenAPI specification, and we can also interactively try the API with the Try Out functionality.
625-
626- 
394+ This section is coming soon. In the meantime, you can follow the [ Traefik Hub API Management quick start guide] ( https://doc.traefik.io/traefik-hub/api-management/quick-start-guide ) tutorial.
0 commit comments