### **Prerequisites** 1. **AWS CLI Installed & Configured** (`aws configure`) 2. **kubectl Installed** 3. **A Running EKS Cluster** (Amazon Elastic Kubernetes Service) 4. **IAM Permissions** to create and manage EKS resources --- ### **Steps to Deploy Kubernetes Deployment to a LoadBalancer in AWS** #### **Step 1: Create an EKS Cluster (If Not Already Running)** ```sh aws eks create-cluster \ --name my-cluster \ --role-arn arn:aws:iam::123456789012:role/EKSClusterRole \ --resources-vpc-config subnetIds=subnet-xxxxxxxx,securityGroupIds=sg-xxxxxxxx ``` This step may take some time. You can verify the cluster status: ```sh aws eks describe-cluster \ --name my-cluster \ --query "cluster.status" ``` #### **Step 2: Update `kubectl` to Use the New Cluster** ```sh aws eks update-kubeconfig --name my-cluster ``` Ensure `kubectl` is using the correct context: ```sh kubectl config current-context ``` #### **Step 3: Deploy an Application** Create a simple deployment file (`deployment.yaml`): ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 2 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: nginx ports: - containerPort: 80 ``` Apply the deployment: ```sh kubectl apply -f deployment.yaml ``` #### **Step 4: Create a LoadBalancer Service** Create a service file (`service.yaml`): ```yaml apiVersion: v1 kind: Service metadata: name: my-app-service spec: type: LoadBalancer selector: app: my-app ports: - protocol: TCP port: 80 targetPort: 80 ``` Apply the service: ```sh kubectl apply -f service.yaml ``` #### **Step 5: Get the LoadBalancer URL** Once deployed, you can get the external IP using: ```sh kubectl get svc my-app-service ``` The output will show something like: ``` NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-app-service LoadBalancer 10.100.200.1 a1b2c3d4.amazonaws.com 80/TCP 5m ``` --- ### **Verifying the Deployment** Check if the pods are running: ```sh kubectl get pods ``` Check logs: ```sh kubectl logs -f ``` Access the application in your browser using the `EXTERNAL-IP`. --- ### **Cleanup** To delete resources: ```sh kubectl delete -f deployment.yaml kubectl delete -f service.yaml aws eks delete-cluster --name my-cluster ```