CI/CD in AWS managed Kubernetes (EKS)

May 18, 2020 in #aws #kubernetes #eks | | | Share on Google+

Run your Docker workload in Kubernetes, managed by AWS cloud, deployed with Terraform, CI/CD Pipeline

Your takeaways from this post

  • Understanding what is a Kubernetes
  • Why a managed Kubernetes (EKS) removes many pain points
  • How to quickly deploy an EKS cluster on AWS, with Terraform
  • CI/CD: a developer push in Github will automatically deploy the new version of the app

Why Kubernetes

When you start working with more than 10 containers, you realize that managing each container on each server is not very optimal:

  • Containers usually don't use all server resources, and if a peak occurs, they are physically stuck on the same hardware
  • If your server crashes, your containers are not restarted on another host
  • Many manual steps are needed if you want to scale up/down similar containers, on multiple hosts

Kubernetes brings solutions to these problems with the following characteristics:

  • Portable: run container in public cloud, on premise (private datacenter), hybrid, multi-cloud, or locally on your laptop
  • Extensible: modular, pluggable, hookable, composable
  • Self-healing: auto-placement, auto-restart, auto-replication, auto-scaling

Even if other solutions exist (Docker Swarm, Mesos, Nomad), Kubernetes (or k8s) - a Google all-star opensource project on Github - is becoming the reference for scheduling and managing containers. Many companies which were already proposing their own orchestration solutions, are now integrating Kubernetes as their container engine.

As a serious contender, we can mention for example Openshift. This RedHat product is leveraging Kubernetes engine framework with additional layers to get to a full PAAS. While winning on ease of use (GUI to pilot the cluster, auto-deploy from registry), it is losing on flexibility (slower Kubernetes updates, integration with other solutions) and community.

Kubernetes alone is then very versatile and powerful. However, it requires a learning curve to understand the concepts and get it running.

AWS proposes another solution to manage containers: Elastic Container Service (ECS). It is a proprietary product but simpler and very well integrated within AWS. Checkout my post comparing Kubernetes and ECS here.

Kubernetes setup

Now that you understand the power of Kubernetes, you need to setup your own cluster in order to start running your container workloads.

Here are the different components:

  • Masters: running Kubernetes master components for container orchestration, they will control, schedule the tasks, record the workload state in etcd and expose an API for developers

  • Nodes: running the actual containers and doing the actual work

Each Kubernetes component has its own lifecycle, needs to be upgraded, and may need troubleshooting when bugs occur. For redundancy, you need at minimum 2 master servers, and at minimum 3 etcd components.

Building a Kubernetes cluster is not trivial even if many tools exist nowadays like kubeadm, kops, automating the deployment and destruction. Upgrading to a major version of the master with an active workload is quite delicate and need some good planning and testing. Troubleshooting the cluster may give you some headaches too as there are many moving parts.

If you want to know more about deploying Kubernetes on premise, checkout this (older) post.

EKS

Now let's introduce EKS, a managed version of Kubernetes in AWS. This cloud provider will then take care of all the problematics listed above: creating, upgrading, troubleshooting your cluster (masters + nodes) so you can concentrate more on deploying containers/pods in a healthy cluster.

EKS internally uses Fargate, ASG and EC2 to be able to run a scalable Kubernetes cluster in AWS.

Nowadays, each major cloud provider proposes its version of managed Kubernetes: Google cloud with [GKE], (https://cloud.google.com/kubernetes-engine/), Microsoft Azure with AKS.

I listed below the difference between each provider:

Deploy EKS

I prepared a demo below to deploy an EKS cluster in AWS, using Terraform. In this cluster, we will deploy a simple helloworld container, with automatic CI/CD from AWS CodePipeline.

Infra

Infra

  • Cloud: AWS
  • EKS: managed Kubernetes container orchestrator (on 3 availability zones for redundancy)
  • ECR: container registry to store hello image
  • App: a simple hello world in nodejs (folder hello)
  • Code source: Github
  • Deployment: Terraform describes all components to be deployed. One command line will setup the infra
  • CI/CD: CodePipeline to build and deploy the app in EKS

CI/CD flow diagram

CI/CD

A simple git push from a developer in Github will launch the whole CI/CD process. Docker image will build and containers in EKS will be updated to run that new image without any downtime.

Get the code

Check out the Github repo to deploy the infra.

Conclusion

  • Today, Kubernetes is the most powerful and standardized way to run container workloads, you are not locked to any vendors and can run on premise, GCP, AWS, Azure and many other locations
  • Letting the cloud vendor taking take of the cluster maintenance (like the service EKS) removes a huge paint points for developers, they can now concentrate on writing application code instead
  • EKS is really simple to manage, it is a great addition to the many services that AWS already propose

Thank you for reading :-) See you in the next post!

May 18, 2020 in #aws #kubernetes #eks | | | Share on Google+