Kubernetes End to End project on EKS
Subham Nandi
Posted on October 4, 2024
To create a detailed article based on the provided information, I’ll reorganize it for clarity and ensure that the technical steps are clearly laid out. Below is the structure for an article on setting up EKS (Elastic Kubernetes Service) on AWS with IAM OIDC provider integration and Fargate profile creation:
Setting Up an EKS Cluster with Fargate and IAM OIDC Integration
Amazon EKS (Elastic Kubernetes Service) is a fully managed Kubernetes control plane that helps simplify deploying, managing, and scaling containerized applications. This article will walk you through the process of creating an EKS cluster with Fargate and integrating it with IAM OIDC (OpenID Connect) for identity management.
1. Creating an EKS Cluster with Fargate
To start, we will create an EKS cluster using the AWS CLI. Fargate allows running Kubernetes pods without having to manage the underlying infrastructure. Here’s how to create your cluster:
eksctl create cluster \
--name demo-cluster \
--region us-east-1 \
--fargate
This command will set up a cluster named demo-cluster
in the us-east-1
region, using Fargate as the compute engine for running your pods.
2. Configuring OpenID Connect (OIDC) Provider for IAM
AWS EKS allows you to use an OpenID Connect (OIDC) provider for authentication, integrating with external identity providers. You can use IAM roles for service accounts to manage access.
Step 1: Associate IAM OIDC Provider with the Cluster
To integrate OIDC, execute the following command:
eksctl utils associate-iam-oidc-provider \
--cluster demo-cluster \
--approve
This command associates the IAM OIDC provider with the demo-cluster
. This is essential for managing IAM roles and policies for service accounts in the cluster.
3. Updating the Kubeconfig
Once the cluster is created, update the kubeconfig
file to access the EKS cluster via kubectl
:
aws eks update-kubeconfig \
--name demo-cluster \
--region us-east-1
4. Creating a Fargate Profile
Next, create a Fargate profile to define which pods should run on Fargate in your EKS cluster:
eksctl create fargateprofile \
--cluster demo-cluster \
--region us-east-1 \
--name alb-sample-app \
--namespace game-2048
This command creates a Fargate profile for the namespace game-2048
, and pods in this namespace will automatically run on Fargate.
5. Deploying Resources with kubectl
To deploy resources in the cluster, apply the Kubernetes manifests. Here’s an example of how to apply a manifest from a GitHub link:
kubectl apply -f kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/examples/2048/2048_full.yaml
Ensure the manifests are correctly set up, especially for deploying your applications or services.
6. Installing the AWS Load Balancer Controller
To expose services outside the cluster, we need an Ingress controller. AWS offers the AWS Load Balancer Controller, which integrates with Elastic Load Balancers (ALB/NLB) to manage ingress for Kubernetes services.
Step 1: Create an IAM Policy for the Controller
First download IAM policy.
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/install/iam_policy.json
Create the IAM policy needed by the AWS Load Balancer Controller:
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam-policy.json
The iam-policy.json
file should define the necessary permissions for the load balancer controller.
Step 2: Associate the IAM Role with the Service Account
Next, associate this IAM policy with a service account in the kube-system
namespace:
eksctl create iamserviceaccount \
--cluster demo-cluster \
--namespace kube-system \
--name aws-load-balancer-controller \
--attach-policy-arn arn:aws:iam::<accountID>:policy/AWSLoadBalancerControllerIAMPolicy \
--approve
This creates a service account that has the necessary permissions to manage AWS load balancers.
Step 3: Install the AWS Load Balancer Controller using Helm
Now install the AWS Load Balancer Controller using Helm:
helm repo add eks https://aws.github.io/eks-charts
helm repo update
helm install aws-load-balancer-controller \
eks/aws-load-balancer-controller \
--namespace kube-system \
--set clusterName=demo-cluster \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller \
--set region=us-east-1 \
--set vpcID=<your_vpc_id>
This command installs the controller and links it to the previously created service account.
7. Verifying the Installation
Once everything is set up, verify that the AWS Load Balancer Controller is running:
kubectl get deployment -n kube-system aws-load-balancer-controller
You should see the deployment running successfully. Additionally, check the status of your pods and services in the game-2048
namespace:
kubectl get pods -n game-2048
kubectl get svc -n game-2048
Ensure that all resources are properly deployed and running.
8. Managing IAM and Ingress
For the Ingress controller to work with IAM roles, ensure that your pods are assigned the necessary permissions. This can be done by associating an IAM OIDC provider and ensuring that the service account used by the ingress controller is correctly configured with the right IAM role.
Conclusion
By following these steps, you’ve successfully set up an EKS cluster with Fargate, integrated IAM OIDC, and deployed an AWS Load Balancer Controller for ingress management. This setup allows for scalable, secure, and manageable Kubernetes deployments on AWS.
This article provides a detailed, step-by-step guide to setting up EKS with IAM OIDC integration and a Fargate profile, ensuring users can deploy applications seamlessly.
Posted on October 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.