We know that when we apply an ingress config, it will create AWS ALB with listener on target groups based on rules. We can basically do this with sample game 2048 at previous post. However, we want to point the domain to the ALB created and also automatically generate listener on port 443 which forwards requests to the target groups.
Thus, we create Route53 Hosted zones and configure A record as below, pointing to the DNS of ALB.
So now api.wito.vn points to our AWS ALB.
Next, we configure yaml file for Ingress.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
alb.ingress.kubernetes.io/certificate-arn: xxx
spec:
ingressClassName: alb
rules:
- host: api.wito.vn
http:
paths:
We need to create the Certificate for SSL, in order to have the certificate-arn as above.
Run kubectl command to apply the configuration.
kubectl apply -f infra/k8s-dev/ingress-srv.yaml
Can take a look on this link for more information about the annnotations. That’s it. It will create for us same listener for both port 80 and 443, pointing to the same target group. In case, it does not create these resources, we need to take a look on the rules. My case is that it does not accept the path like /?(.*). Go to Ingress section in your cluster to find the error message.