Deploy to AWS EKS (Kubernetes)

The following guide shows how to deploy your application to AWS Elastic Kubernetes Service (EKS) Cluster using the aws-eks-kubectl-run pipe and Bitbucket Pipelines.

We’ll use Bitbucket Pipelines to build and push a docker image to a container registry (Docker Hub). Also, we will show how to configure it to automate the deployments to Kubernetes.

Prerequisites

To deploy your application with aws-eks-kubectl-run pipe you’ll need to have:

  • An IAM user is configured with sufficient permissions to allow the pipe to perform a deployment to your application and upload updates to the AWS EKS cluster.

  • An AWS EKS cluster configured for the application: Getting Started with eksctl.

  • You have configured a Worker Node Group. Here is a simple tutorial from AWS: Creating the Amazon EKS Worker Node IAM Role.

  • DockerHub account with the ability to push and pull images.


Steps

1. Configure your Bitbucket repository

2. Add your credentials and configuration settings in Bitbucket as variables. See: how to configure Pipelines variables.

Variable nameValue
DOCKERHUB_USERNAME

Your DockerHub username.

DOCKERHUB_PASSWORD

Your DockerHub password.

AWS_ACCESS_KEY_ID

Your AWS access key.

AWS_SECRET_ACCESS_KEY

Your AWS secret access key. Make sure that you save it as a secured variable.

AWS_DEFAULT_REGION

The AWS region code (us-east-1, us-west-2, etc.) of the region containing the AWS resources. For more information, see Regions and Endpoints.


3. Setup your CI/CD configuration by editing your bitbucket-pipelines.yml file


image: atlassian/default-image:2

pipelines:
  default:
    - step:
        name: "Build and push"
        services:
          - docker
        script:
          - IMAGE="bitbucketpipelines/hello-app-eks"
          - VERSION="${BITBUCKET_BUILD_NUMBER}"
          - echo ${DOCKERHUB_PASSWORD} | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
          - docker build -t ${IMAGE} .
          - docker tag ${IMAGE} ${IMAGE}:${VERSION}
          - docker push ${IMAGE}
    - step:
        name: "Deploy to PROD"
        deployment: production
        script:
          - envsubst < helloweb-deployment.tpl.yaml > helloweb-deployment.yaml
          - pipe: atlassian/aws-eks-kubectl-run:1.2.0
            variables:
              AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
              AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
              AWS_DEFAULT_REGION: "us-east-2"
              CLUSTER_NAME: "hello-cluster"
              KUBECTL_COMMAND: "apply"
              RESOURCE_PATH: "helloweb-deployment.yaml"
              DEBUG: "true"

This configuration allows you to build and push the image to Docker Hub, then use deployments with the aws-eks-kubectl-run pipe in order to automate deployments to Kubernetes. Learn more about how to edit and configure your Bitbucket pipelines configuration.

4. Deploy the application to production. Push your application’s code to your Bitbucket repository which will trigger the pipeline. You can then select Pipelines to check pipeline progress and verify that the application was successfully deployed.

Note

aws-eks-kubectl-run pipe can be used with other pipes to create your great CI/CD pipelines.


Example

A full end-to-end example is available in this example repository, you can check it for more details about how to deploy to AWS EKS using Pipelines and Pipes.


Last modified on Feb 4, 2020

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.