Deploy docker container in Kubernetes (EKS)
Basics of deploying a container in Kubernetes pod
DEVOPSDOCKERKUBERNETES


What is Kubernetes?
Imagine you're a manager at a small restaurant that serves a variety of dishes. You have a team of chefs who cook the food, and you have a limited number of stoves in the kitchen.
Initially, you might manually assign each chef to a stove and keep an eye on everything yourself. But as your restaurant becomes popular and you start getting more customers, managing the kitchen manually becomes difficult. Kubernetes acts as an automated kitchen manager, making sure that your restaurant runs smoothly even during busy times, while allowing you to focus on serving delicious food to your customers.
By definition, Kubernetes is an open-source container orchestration platform. It automates the deployment, scaling, and management of containerized applications. Now that you have some picture of why we use Kubernetes, lets move on to a quick hands on exercise for deploying your container on Kubernetes. For this exercise we will use EKS which is AWS managed Kubernetes service and AWS CloudShell for interacting with the cluster.
Exercise
Pre-requisites:
An AWS account with user that has AdministratorAccess policy attached. Please note that we are using CloudShell for interacting with EKS through kubectl here and this is not the lowest level access. This is not recommended outside test environment. Please read more on IAM policies and users to attach lowest level policies needed here.
Super simplified 3 steps for this exercise:
Create an EKS cluster: EKS in us-east-1 costs $0.10/hr as of today. This cost is incurred for running the master node and other services. So please make sure to delete the cluster later. We have already discussed the steps to create/delete cluster using eksctl and interact with it using kubectl here.
Create new or use existing docker image: We need a docker image to run container. For current exercise, we will use this image. To get more details on how to containerize your application, refer here.
Please note that docker is pre installed on CloudShell. Use "docker pull hello-world" to pull the image in local. Test if the image is available using "docker images".
Run the container in Kubernetes: Please note that kubectl is also preinstalled in CloudShell. Since you just created your cluster using eksctl, your kubectl is already pointing to that cluster. If you have multiple clusters and want to point to a different cluster, please use "aws eks --region <region> update-kubeconfig --name <my-cluster>".
Now create a file called pod.yaml (any name can be used in prefix) and add below code to it. Now simply run, "kubectl apply pod.yaml". This will create a pod which is running the container and you can check the same with "kubectl get pods".
Congratulations on your first pod deployment!!