# Ingress and AWS Load Balancer Controller

## <mark>Ingress</mark>

By default when you create the cluster using cli , It creates the classic load balancer. We need to explicitly tell the cluster that to create the ALB.\
\
Ingress is a resource that tells the Aws Load Balancer controller to create the alb with some rules. That rules we will provide in the ingress resource in the annotations section.\
\
Aws Load Balancer Controller is the driver which can create the alb , listener , rule and we should attach the service account to this controller pod where it runs in the kube-system namespace.

Please once check the ingress definition.

```plaintext
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-alb
  namespace: roboshop
  annotations:
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS": 443}]'
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:337756367047:certificate/05f742247-d22d9-4aa4523f-bwef8e7-82a613e3452aff2
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/tags: Environment=dev,Project=roboshop
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.name: roboshop
spec:
  ingressClassName: alb
  rules:
  - host: "vijayaws2.fun"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: frontend
            port:
              number: 80
```

## <mark>Steps</mark>

1. Associate the cluster with the <mark>OIDC</mark> provider

   ```plaintext
   eksctl utils associate-iam-oidc-provider \
       --region us-east-1 \
       --cluster roboshopcluster \
       --approve
   ```
2. Download the IAM policy

   ```plaintext
   curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.16.0/docs/install/iam_policy.json
   ```
3. Create the IAM policy

   ```plaintext
   aws iam create-policy \
       --policy-name AWSLoadBalancerControllerIAMPolicy \
       --policy-document file://iam-policy.json
   ```
4. Create Service account and IAM role and attach the above policy

   ```plaintext
   eksctl create iamserviceaccount \
   --cluster=roboshopcluster \
   --namespace=kube-system \
   --name=aws-load-balancer-controller \
   --attach-policy-arn=arn:aws:iam::337756367047:policy/AWSLoadBalancerControllerIAMPolicy \
   --override-existing-serviceaccounts \
   --region us-east-1 \
   --approve
   ```
5. Install Helm

   ```plaintext
   sudo dnf install helm
   ```
6. Add the repo

   ```plaintext
   helm repo add eks https://aws.github.io/eks-charts
   ```
7. Install the aws load balancer controller , Its runs as the pods in the kube-system namespace.

   ```plaintext
   helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --set clusterName=roboshopcluster --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
   ```

## <mark>Demo Images:</mark>

![](https://cdn.hashnode.com/uploads/covers/66d950bc53b6fbeba2093f57/8b4719ad-9c49-40c5-be46-9f7472456e1a.png align="center")

![](https://cdn.hashnode.com/uploads/covers/66d950bc53b6fbeba2093f57/289a9140-6691-45ec-9283-c136cf0444b6.png align="center")

![](https://cdn.hashnode.com/uploads/covers/66d950bc53b6fbeba2093f57/842c8611-8881-4ce0-8777-e80450e8b0e2.png align="center")

![](https://cdn.hashnode.com/uploads/covers/66d950bc53b6fbeba2093f57/c979ce26-f4cb-4e0c-829f-222bd88c2e05.png align="center")

\
**<mark>Architecture Diagram :</mark>**

![](https://cdn.hashnode.com/uploads/covers/66d950bc53b6fbeba2093f57/e73df178-d251-46b4-a5a4-2c3d5b38c05f.png align="center")

- Here aws load balancer controller creates the alb , listener , rule , target group.
- Even the controller is responsible to attach the endpoints of the service to the target group, So that target group can send the request directly to the pods.

GitHub : <https://github.com/vija-web/Kubernetes-/tree/master/Ingress>

Thank You :)
