Understanding Kubernetes and Its Role with Docker
Bhargavi Bairagoni
"Aspiring DevOps Engineer | Skilled in AWS, Python, Java, HTML, Database Management, and Linux"
In this article, we will explore the essential concepts of Kubernetes and Docker, two pivotal technologies in the realm of containerization. We will discuss what Kubernetes is, its architecture, and its relationship with Docker. Additionally, we will cover the advantages and disadvantages of using Docker, the types of Kubernetes clusters, and practical commands for installing and deploying applications in Kubernetes. By the end of this article, you will have a clearer understanding of how these technologies work together to enhance application deployment and management.
What is Docker with Kubernetes?
Docker is an open-source container orchestration platform. It helps automate the deployment, scaling, and management of containerized applications. Docker revolutionized the way we build and deploy applications by packaging them into containers, but Kubernetes takes it a step further by managing the containers across multiple servers (or clusters).
Another Name for Kubernetes
Kubernetes is often abbreviated as K8s, where the "8" represents the eight letters between the "K" and the "s."
Docker with Kubernetes:
Docker serves as the platform for building and packaging applications into containers (the ship), while Kubernetes orchestrates and manages those containers at scale (the steering wheel), ensuring they run efficiently across clusters of servers.
Docker is a platform used to develop, ship, and run applications inside containers. It enables developers to package their applications with all dependencies into a single, lightweight container.
When Docker is combined with Kubernetes, you get a powerful system that not only packages and isolates your applications (Docker) but also manages the deployment, scaling, and monitoring of these containers (Kubernetes).
Disadvantages of Using Docker Alone:
While Docker is a powerful tool, it has its limitations, especially when used in larger, distributed environments. Some of the key disadvantages are:
Advantages of Kubernetes (K8s):
Kubernetes Architecture
Understanding Kubernetes' architecture is essential to grasp how it manages applications. Below are the critical components of Kubernetes:
Kubernetes Primary (Master Node):
The main control unit that manages the cluster.
Kubernetes Node:
A worker machine in Kubernetes where containers are deployed.
What is a Cluster?
A cluster is a group of servers (nodes) that work together to run applications. There are two main types of clusters:
Self-Managed Cluster: A cluster managed by the user, where they handle the installation and maintenance of Kubernetes components.
Cloud-Managed Cluster: A cluster provided and maintained by cloud providers (e.g., Google Kubernetes Engine, Amazon EKS).
What are Controllers?
Controllers in Kubernetes are responsible for managing the state of the cluster. Some common types include:
Monitoring and Grace Periods
Kubernetes controllers periodically monitor the cluster state (5 sec), checking whether the actual state matches the desired state. If discrepancies are found, the controller takes action to correct them.
The grace period is the time (40 sec) Kubernetes waits before taking action on a failing resource, allowing for temporary issues to resolve.
What is Minikube?
Minikube is a tool that allows you to run Kubernetes locally on a single-node cluster. It is particularly useful for developers who want to experiment with Kubernetes without needing a full multi-node setup.
领英推荐
Types of Kubernetes Installation
Commands to Install Minikube
To install Minikube, you can follow these steps:
apt update -y
sudo apt install curl wget apt-transport-https -y
sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo mv minikube-linux-amd64 /usr/local/bin/minikube
sudo chmod +x /usr/local/bin/minikube
sudo minikube version
sudo curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
sudo echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
sudo minikube start --driver=docker --force
Deploying an Application in Kubernetes
To deploy an application, you need to create a pod using the following command:
kubectl run podname --image=imagename
Listing Pods
To view the list of running pods, use the following command:
kubectl get pods
Declarative Way to Create a Pod
You can create a pod using a YAML file (pod.yml) with the following content:
---
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: cont1
image: nginx
ports:
- containerPort: 80
To create the pod, run:
kubectl create -f pod.yml