Kubernetes cluster setup and ingress configuration
Hello and welcome back to the blog ! Today we are going to set up Kubernetes clusters on AWS , and then discuss how we can expose the apps via Ingress.
While Kubernetes fundamentals will be covered in another post , you are expected to have a basic understanding of Kubernetes if you want to go ahead with this article.
At the highest level of abstraction, a kubernetes cluster contains a Control plane and a data plane. Control plane contains components that help manage the data plane .Data plane consists of worker nodes which host applications in pods.
Cluster setup on EKS.
Creating Roles:
In order to create an EKS cluster, we first need to create two IAM roles.
- Cluster service role [ AWS Service: eks ]
AmazonEKSClusterPolicy
2.Node IAM role [ AWS Service: ec2 ]
EKSWorkerNode
Ec2ContainerRegistryReadOnly
AmazonEKS_CNI_Policy
Creating Cluster:
From the list of services, you can select EKS and choose the correct region you want to deploy your cluster in.
After clicking on Create cluster, you can give it a name, assign the created Cluster service role, select VPC , the subnets you want to deploy in, the security groups associated with the subnets and the default addons for networking. Once done, review and create the cluster. This will take a few minutes and create a control plane. Keep in mind that this still does not have any nodes or data plane. For that we will need to go to the next step – creating a node group
Creating NodeGroup
So once the cluster is created, we can go to the configuration tab and create a new NodeGroup. Give it a name, assign it the Node IAM role that we created previously. It is just Ec2 instance configuration. You can select desired count and request the nodes.
You can connect to this cluster using the AWS Cli. Now lets see the setup in AKS. Once both cluster setup is done, we can talk about the deployments and ingress
Creating a deployment and a service
Using the default templates from Kubernetes.io, you can create a sample deployment and a service that is associated with that deployment . You can use the ClusterIP instead of LoadBalancer for the service type, because you want to expose the service via ingress and not directly via load balancer.
Ingress Setup on a Kubernetes cluster
After the deployments are completed, we can configure the ingress. The first thing we need to do is set up an ingress controller [ We will use nginx-ingress]. This controller interacts with the Kube api , and manages creation of load balancers. [https://www.nginx.com/products/nginx-ingress-controller/]
Lets install helm first and then we can create the chart for nginx-ingress
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install nginx-ingress ingress-nginx/ingress-nginx
The ingress controller load balancer address will be used in the CNAME/A records in our domain registrar.
Once the ingress controller is set up, we should be able to create an ingress successfully.
Creating Ingress
You should provide the correct set of annotations in the ingress file which is used by ingress-controller to create the load balancer.
It needs to have a backend path, with a path pattern and port. You can use one of the ingress templates from Kubernetes.io