Once we have created a Docker Container which has all of our application files and its dependencies, it is time to deploy it, but most of the times it is not enough to deploy a single container, if we want to provide the best service we might need to provide more instances of a container when the demand if high and shut down extra containers when they are no longer needed.
To do so we need a software orchestration service, and at the time of writing this, the most popular one is Kubernetes.
Kubernetes Cluster: is a group of machines running Kubernetes
Kubernetes Master: is the system which controls the whole cluster, all the machines in the cluster are controlled by the Kubernetes Master.
Kubernetes Node: a single machine from the Kubernetes Cluster, nodes can be physical or virtual machines, or a combination of both.
Pod: is the smallest unit of the Kubernetes architecture and it is a single deployment of a containerised app, which includes the container, storage resources and a unique IP address
Service: a set of pods of the same application which provides a way to communicate with them
Amazon Elastic Kubernetes Service (a.k.a. EKS)
Is a managed Kubernetes Service provided by Amazon, which eliminates the headaches of setting up the cluster.
Read more about EKS here: What is Amazon EKS?
Installing the AWS CLI
A very easy way to do it is with pip:
pip install awscli --upgrade
Once installed we need to configure it with the access credentials.
Which we will need to have already created in the AWS IAM Console > Users > Find the user to use and create an access key.
Make sure to copy the access key as we will use it in the terminal to configure AWS CLI.
Back to the terminal to configure the access credentials we need to type in:
aws configure --profile default
Follow the wizard and fill in the requested data.
Once configured test it by listing all s3 buckets in the account:
aws s3 ls
eksctl – The official CLI for Amazon EKS
To create a cluster in AWS we will use EKS through the command line.
Eksctl is a tool specifically designed to simplify the EKS cluster creation process.
From the official eksctl site:
eksctlis a simple CLI tool for creating clusters on EKS – Amazon’s new managed Kubernetes service for EC2.
curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin
brew tap weaveworks/tap brew install weaveworks/tap/eksctl
chocolatey install eksctl
Kubectl is a command line tool for interacting with a Kubernetes clusters and it’s components such as pods and services.
It is normally installed for us automatically when installing docker, to check if it is installed type:
If the command was not found then proceed to install it with the instructions provided by the official Kubernetes site here: https://kubernetes.io/docs/tasks/tools/install-kubectl/
Create and EKS Cluster
To create the cluster using eksctl run the following command:
eksctl create cluster --name your-cluster-desired-name
The creation of the cluster can take some time so just be patient.
We can find the resources that were created in the AWS console under CloudFormation
We can also check the cluster status with kubectl by typing:
kubectl get nodes
Deleting the cluster
The resources we just created with eksctl are not free, so if they are not going to be used it is better to delete them to avoid being charged by AWS
To delete it with eksctl just type:
eksctl delete cluster your-cluster-name