Comment utiliser les certificats de protocole TLS pour activer les connexions HTTPS pour mes applications Amazon EKS ?

Lecture de 4 minute(s)
0

Je souhaite utiliser des certificats de protocole TLS (Transport Layer Security) pour activer les connexions HTTPS pour mes applications Amazon Elastic Kubernetes Service (Amazon EKS).

Brève description

Pour activer les connexions HTTPS pour vos applications Amazon EKS, vous devez :

  • Obtenez un certificat TLS valide pour votre domaine personnalisé.
  • Exposez votre service Kubernetes à l'aide du type de service d'équilibrage de charge, ou exposez votre objet d'entrée Kubernetes à l'aide d'AWS Load Balancer Controller (sur GitHub).
  • Associez votre domaine personnalisé au DNS de l'équilibreur de charge.

Résolution

Obtenez un certificat TLS valide pour votre domaine personnalisé :

1.    Demandez un certificat AWS Certificate Manager (ACM) public pour votre domaine personnalisé, ou chargez votre propre certificat TLS sur ACM.

2.    Identifiez le nom de ressource Amazon (ARN) du certificat que vous souhaitez utiliser avec l'écouteur HTTPS de l'équilibreur de charge.

3.    Pour créer un exemple de déploiement NGINX, exécutez la commande suivante :

$ kubectl create deploy web --image=nginx --port 80 --replicas=3

4.    Pour vérifier que les pods Kubernetes sont déployés sur votre cluster Amazon EKS, exécutez la commande suivante :

$ kubectl get pods -l app=web

**Remarque :**Les pods sont étiquetés app=web. Utilisez cette étiquette comme sélecteur pour l'objet de service afin d'identifier un ensemble de pods.

Exposez votre service Kubernetes à l'aide du type de service d'équilibrage de charge

Remarque :Pour utiliser l'objet d'entrée afin d'exposer votre application, passez à la section Exposez votre service Kubernetes à l'aide de l'objet d'entrée.

1.    Pour créer un fichier manifeste service.yaml, utilisez le type de service LoadBalancer :

cat <<EOF > loadbalancer.yaml
apiVersion: v1
kind: Service
metadata:
  name: lb-service
  annotations:
    # Note that the backend talks over HTTP.
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
    # TODO: Fill in with the ARN of your certificate.
    service.beta.kubernetes.io/aws-load-balancer-tls-cert: arn:aws:acm:{region}:{user id}:certificate/{id}
    # Only run TLS on the port named "https" below.
    service.beta.kubernetes.io/aws-load-balancer-tls-ports: "https"
    # By default In-tree controller will create a Classic LoadBalancer if you require a NLB uncomment below annotation.
    # service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
spec:
  selector:
    app: web
  ports:
  - name: http
    port: 80
    targetPort: 80
  - name: https
    port: 443
    targetPort: 80
  type: LoadBalancer
EOF

2.    Modifiez l'annotationservice.beta.kubernetes.io/aws-load-balancer-tls-cert pour inclure l'ARN de l'ACM.

3.    Pour appliquer le fichier loadbalancer.yaml, exécutez la commande suivante :

$ kubectl create -f loadbalancer.yaml

4.    Passez directement à la section Associer votre domaine personnalisé au DNS de l'équilibreur de charge.

Exposez votre service Kubernetes à l'aide de l'objet d'entrée

**Remarque :**La résolution suivante suppose que vous avez installé AWS Load Balancer Controller dans votre cluster Amazon EKS.

1.    Créez un service Kubernetes de type NodePort en vous basant sur l'exemple suivant :

cat  <<EOF  > ingressservice.yaml
apiVersion: v1
kind: Service
metadata:
  name: web-nginx
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    app: web
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: "web-nginx-ingress"
  annotations:
    # Below annotation is to specify if the loadbalancer is "internal" or "internet-facing"	   
    alb.ingress.kubernetes.io/scheme: internet-facing
    # TODO: Fill in with the ARN of your certificate.
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-west-2:xxxx:certificate/xxxxxx
    # TODO: Fill in the listening ports.
    alb.ingress.kubernetes.io/listen-ports: '\[{"HTTP": 80}, {"HTTPS":443}\]'
    # Set HTTP to HTTPS redirects. Every HTTP listener configured will be redirected to below mentioned port over HTTPS.
    alb.ingress.kubernetes.io/ssl-redirect: '443'
  labels:
    app: web
spec:
  ingressClassName: alb
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: "web-nginx"
                port:
                  number: 80
EOF

**Remarque :**Le manifeste d'entrée précédent écoute sur HTTP et HTTPS, puis met fin au protocole TLS sur ALB et redirige le HTTP vers le protocole HTTPS.

2.    Pour appliquer le fichier ingressservice.yaml, exécutez la commande suivante :

$ kubectl create -f ingressservice.yaml

Associez votre domaine personnalisé au DNS de l'équilibreur de charge

1.    Pour renvoyer l'URL DNS du service de type LoadBalancer, exécutez la commande suivante :

$ kubectl get service

2.    Pour renvoyer l'URL DNS du service de type Ingress, exécutez la commande suivante :

$ kubectl get ingress/web-nginx-ingress

3.    Associez votre nom de domaine personnalisé au nom de votre équilibreur de charge.

4.    Dans un navigateur Web, testez votre domaine personnalisé à l'aide du protocole HTTPS suivant :

https://yourdomain.com
AWS OFFICIEL
AWS OFFICIELA mis à jour il y a un an