Skip to content
Latchkey

How to Deploy to Amazon EKS With kubectl in CircleCI

Run aws eks update-kubeconfig to write cluster credentials, then kubectl apply and kubectl rollout status to ship and confirm the deploy.

Authenticate to EKS by writing a kubeconfig with aws eks update-kubeconfig, set the new image, and block on kubectl rollout status.

Steps

  • Install kubectl and the AWS CLI in the executor.
  • Run aws eks update-kubeconfig --name <cluster>.
  • Set the deployment image to the freshly built tag.
  • Wait for kubectl rollout status to confirm success.

Config

.circleci/config.yml
version: 2.1
jobs:
  deploy:
    docker:
      - image: cimg/aws:2024.03
    steps:
      - checkout
      - run:
          name: Configure kubeconfig
          command: aws eks update-kubeconfig --name "$EKS_CLUSTER" --region "$AWS_REGION"
      - run:
          name: Roll out new image
          command: |
            kubectl set image deployment/api \
              api="$ECR_REPO:$CIRCLE_SHA1" -n production
            kubectl rollout status deployment/api -n production --timeout=120s
workflows:
  ship:
    jobs:
      - deploy:
          context: aws-prod

Gotchas

  • The IAM identity must be in the cluster aws-auth ConfigMap or the access entries, or kubectl returns a 401.
  • rollout status exits non-zero on timeout, which fails the job so a stuck deploy does not pass silently.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →