Docker to Kubernetes Migration MEGA PROJECT


TOPICS COVERED
Docker Architecture
Kubernetes Architecture
Docker to kubernetes Migration
Kubernetes Components
K8 ConfigMaps
K8 Persistent Volumes
K8 Secrets
K8 Deployments
K8 Service
Namespace
Database deployments
K8 Persistent Volumes Claims
Docker Architecture
Kubernetes Architecture
Cluster Architecture
A Kubernetes cluster consists of a control plane plus a set of worker machines, called nodes, that run containerized applications. Every cluster needs at least one worker node in order to run Pods.
Control plane components
1) Kube-apiserver The API server is a component of the Kubernetes control plane that exposes the Kubernetes API. The API server is the front end for the Kubernetes control plane.
2) Etcd Consistent and highly-available key value store used as Kubernetes' backing store for all cluster data.
3) kube-scheduler Control plane component that watches for newly created Pods with no assigned node, and selects a node for them to run on.
4) kube-controller-manager
There are many different types of controllers. Some examples of them are:
● Node controller: Responsible for noticing and responding when nodes go down.
● Job controller: Watches for Job objects that represent one-off tasks, then creates Pods to run those tasks to completion.
● EndpointSlice controller: Populates EndpointSlice objects (to provide a link between Services and Pods).
● ServiceAccount controller: Create default ServiceAccounts for new namespaces.
Node components
A Kubernetes cluster consists of a control plane plus a set of worker machines, called nodes, that run containerized applications. Every cluster needs at least one worker node in order to run Pods.
Control plane components
1) kubelet: An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.The kubeket takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy. The kubelet doesn't manage containers which were not created by Kubernetes.
2) kube-proxy : kube-proxy is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes Service concept.kube-proxy maintains network rules on nodes. These network rules allow network communication to your Pods from network sessions inside or outside of your cluster.
3) Container runtime : A fundamental component that empowers Kubernetes to run containers effectively. It is responsible for managing the execution and lifecycle of containers within the Kubernetes environment.
4) Pods
Docker to kubernetes Migration
Why Move from Docker Compose to Kubernetes
Single-cluster limitation of Compose
Docker Compose containers run on a single host. When multiple hosts or cloud providers are used to run an application workload, this presents a network communication challenge. Using Kubernetes, you can manage multiple clusters and clouds more easily.
Single point of failure in Compose
Docker Compose-based applications require that the server running the application be kept running for them to continue working. This leads to a single point of failure on the server running Compose. Contrary to this, Kubernetes runs typically in a highly available (HA) state with multiple servers deploying and maintaining the applications. The nodes are also scaled based on resource utilization in Kubernetes.
The extensibility of Kubernetes
Platforms like Kubernetes are highly extensible, which is why they are popular with developers. Pods, Deployments, ConfigMaps, Secrets, and Jobs are some native resource definitions. Clustered applications run using each of them for different purposes. The Kubernetes API server provides the ability to use CustomResourceDefinition to add custom resources.
open source support of Kubernetes
Kubernetes is a powerful platform that continues to grow rapidly among enterprises. Over the past two years, it has ranked among the most popular platforms and the most desired among software developers. It stands out among container orchestration and management tools.
K8 Deployments / Services
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
K8 ConfigMaps
A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume
K8 Secrets
A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a Pod specification or in a container image. Using a Secret means that you don't need to include confidential data in your application code.
apiVersion: v1
kind: Secret
metadata:
name: secret-basic-auth
type: kubernetes. io/basic-auth
stringData:
username: admin # required field for kubernetes.io/basic-auth
password: t0p-Secret # required field for kubernetes.io/basic-auth
apiVersion: v1
kind: Secret
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: "sa-name"
type: kubernetes. io/service-account-token
data:
extra: YmFyCg ==
PV & PVC in Kubernetes
The main difference between PV and PVC is that PV represents a piece of storage in a cluster, while PVC represents a request for storage by a pod
KUBERNETES PROJECT HANDSON
Now here we started our main project Handson
STEP 1
TAKE THE LINUX2 AMI EC2 WITH 20 GB AND T2.MEDIUM
STEP 2
Fire below command on terminal
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl enable docker
sudo yum install conntrack -y
sudo yum install git -y
STEP 3
- Download Minikube
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
STEP 4 -
sudo install minikube-linux-amd64 /usr/local/bin/minikube
sudo chmod 777 /var/run/docker.sock
/usr/local/bin/minikube start --force --driver=docker
STEP 5
clone our project from git-hub
change directory
cd /opt
sudo git clone https://github.com/divyasatpute/docker-kubernates-migration.git
STEP 6 -
Install kubectl
sudo curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.20.4/2021-04-12/bin/linux/amd64/kubectl
sudo chmod +x ./kubectl
mkdir -p $HOME/bin
cp ./kubectl $HOME/bin/kubectl
export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
source $HOME/.bashrc
kubectl version --short –client
STEP 7 -
cd Kubernetes folder and create the namespace
cd docker-kubernates-migration/
cd kubernetes/
kubectl apply -f namespace.yaml
STEP 8
Verify the namespace
kubectl get ns
STEP 9 -
Create the configmap
kubectl apply -f configmap.yaml
STEP 10 -
Create the Secrets
kubectl apply -f secret.yaml
STEP 11
Create the Persistent volume
kubectl apply -f persistent-volume.yaml
STEP 12
Create the Persistent volume claim
kubectl apply -f persistent-volume-claim.yaml
STEP 13 -
Create the web deployment
kubectl apply -f web-deployment.yaml
STEP 14
kubectl apply -f db-deployment.yaml
STEP 15 -
- Create the service for web app DB
kubectl apply -f web-service.yaml
kubectl apply -f db-service.yaml
Test Result
pod successfully up and running
Subscribe to my newsletter
Read articles from Divya vasant satpute directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Divya vasant satpute
Divya vasant satpute
, I'm a seasoned DevOps engineer 🛠️ with a knack for optimizing software development lifecycles and infrastructure operations. 💡 Specializing in cutting-edge DevOps practices and proficient in tools like Docker, Kubernetes, Ansible, and more, I'm committed to driving digital transformation and empowering teams to deliver high-quality software with speed and confidence. 💻