Posts Tagged

aws

Kubernetes on AWS: Setting up a cluster on Amazon Web Services (with Amazon EKS)

Kubernetes on AWS: Setting up a cluster on Amazon Web Services (with Amazon EKS)

Prerequisites

  • An AWS account with administrative access
  • A basic understanding of Kubernetes concepts
  • A local machine with the aws and kubectl command-line tools installed

Step 1: Create an Amazon EKS Cluster

  • Open the AWS Management Console and navigate to the EKS console.
  • Click on “Create cluster”.
  • Choose a name for your cluster and select the region where you want to create it.
  • Choose the Kubernetes version you want to use.
  • Choose the type of control plane you want to use: either managed or self-managed.
  • Select the number of nodes you want to create in your cluster.
  • Choose the instance type and size for your nodes.
  • Choose the networking options for your cluster.
  • Review your settings and click on “Create”.

Step 2: Configure kubectl

  • Install the aws CLI tool if you haven’t already done so.
  • Run the following command to update your kubectl configuration:
  • aws eks update-kubeconfig --name my-cluster --region us-west-2
  • Replace my-cluster with the name of your EKS cluster, and us-west-2 with the region where your cluster is located.
  • This command updates your kubectl configuration to use the AWS IAM user or role that you used to create your cluster. It also sets the current context to your EKS cluster.

Step 3: Verify Your Cluster

kubectl get nodes

Step 4: Deploy Applications to Your Cluster

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
  type: LoadBalancer
kubectl apply -f nginx.yaml