Continuous Deployment with Gitlab CI/CD, Helm and AWS EKS

Stanislas Randriamilasoa
2 min readDec 15, 2020
Go! Go! k8s

The main purpose of this post is to show you how to setup a deployment job using Gitlab CI, helm, and AWS EKS.

No more word, I show you directly the content of the .gitlab-ci.yml !

stages:
- deploy_prod
.tags_only:
only:
refs: &tags_only
- tags
.deploy_all: &deploy_all
stage: deploy
image: dtzar/helm-kubectl:3.3.4
before_script:
- curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
- mv /tmp/eksctl /usr/local/bin
- eksctl version
- curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/aws-iam-authenticator
- chmod +x ./aws-iam-authenticator
- mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin
- echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile
- aws-iam-authenticator help
deploy_production:
<<: *deploy_all
only:
refs: *tags_only
stage: deploy_prod
environment: production
when: manual
script:
- eksctl utils write-kubeconfig --kubeconfig kubeconfig-$CLUSTER_NAME.yaml --cluster $CLUSTER_NAME --region $AWS_DEFAULT_REGION
- export KUBECONFIG=${PWD}/kubeconfig-$CLUSTER_NAME.yaml
- kubectl get nodes

In this example:

  • Deployment will be triggered manually on Git tag
  • If everything is ok, you will see the list of nodes in your cluster after kubectl get nodes command line

Before launching the script, you should insert the following Env variable to gitlab CI/CD variables list.

CLUSTER_NAME=<EKS_CLUSTER_NAME>
AWS_ACCESS_KEY_ID=<IAM_ACCESS_KEY_ID>
AWS_SECRET_ACCESS_KEY=<IAM_SECRET_KEY>
AWS_DEFAULT_REGION=<AWS_DEFAULT_REGION(i.e. us-west-1)>

Now, try to push and tag on gitlab!

That’s all! I hope this is helpful for someone who are new in EKS and Gitlab CI.

In the next post we will see how to update a micro-service with Helm and Gitlab-ci.

There is another way to deploy application to AWS EKS with Gitlab CI/CD, you can find more information about it HERE

--

--