Files
2025-10-27 22:21:32 +03:00

2.4 KiB

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)

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:

aws eks describe-cluster \
	--name my-cluster \
	--query "cluster.status"

Step 2: Update kubectl to Use the New Cluster

aws eks update-kubeconfig --name my-cluster

Ensure kubectl is using the correct context:

kubectl config current-context

Step 3: Deploy an Application

Create a simple deployment file (deployment.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:

kubectl apply -f deployment.yaml

Step 4: Create a LoadBalancer Service

Create a service file (service.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:

kubectl apply -f service.yaml

Step 5: Get the LoadBalancer URL

Once deployed, you can get the external IP using:

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:

kubectl get pods

Check logs:

kubectl logs -f <pod-name>

Access the application in your browser using the EXTERNAL-IP.


Cleanup

To delete resources:

kubectl delete -f deployment.yaml
kubectl delete -f service.yaml
aws eks delete-cluster --name my-cluster