Introduction
Kubernetes, also known as K8s, has emerged as a popular container orchestration platform that has revolutionized the way modern applications are developed, deployed, and managed.
What is Kubernetes?
Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications.
Key Concepts of Kubernetes:
Nodes: Nodes are the worker machines that run containers. They can be physical or virtual machines and form the foundation of the Kubernetes cluster.
Pods: Pods are the smallest and simplest units in the Kubernetes object model. A pod represents a single instance of a running process in a cluster and can contain one or more containers.
Services: Services provide a stable IP address and DNS name to a set of pods, allowing them to be accessed by other pods or external users.
Volumes: Volumes are used to store data that needs to persist beyond the lifetime of a pod. They can be used to share data between containers in the same pod or between different pods.
Labels and Selectors: Labels are used to attach metadata to Kubernetes objects, such as pods, services, and volumes. Selectors are used to filtering and select objects based on their labels, enabling advanced deployment strategies.
Replica Sets: Replica Sets are used to ensure that a specified number of pods are running and maintain the desired state of the application. They can scale up or down the number of pods based on defined rules.
Config-Maps: Config-Maps are intended for nonsensitive data, and Config data (Config files and Variables). They can be created and shared in containers in the same way as secrets. The major difference is base 64 encoding.
Persistent Volumes: Persistent Volumes (PVs) are a way of maintaining cluster-wise resources where data is preserved behind the pod life cycle.
Persistent Volume Claim: It is a request for storage by a user (similar to pods). Pods consume node resources and PVCs consume PV resources. Pods can have a specific level of requests.
Health Checks:
Readiness Probe (RP): In some cases, we would like our apps to be alive but not serve the traffic unless some conditions are met, in such cases we use RP, if the condition inside RP passes then only our applications can serve the traffic.
Liveness Probe (LP): It doesn't wait for RP to succeed. If you want to wait before executing LP you should use initial delay seconds.
Deployments
It is a K8 object used to manage pods. Without deployment, you need to create, update, and delete a bunch of pods manually. With deployment, we will create a single object in a manifest file. This object is responsible for creating pods, making sure pod states is up to date, and ensuring there are enough running pods are available.
Deployments types:
Rolling update: It is a default deployment strategy and it is a popular strategy for updating containerized applications without downtime. It allows for a controlled and automated way to roll out changes to containers or container images in a gradual and incremental manner.
Canary deployment: It can be done by using two deployments with common pod labels. One replica of the new version is released along with the old versions. It allows organizations to test in a prod environment with real users and use cases and compares different service versions. It is cheaper than blue-green deployment. Because it doesn't require two production environments.
Blue Green deployments: It offers the IT operations team with greater opportunity to test a new release before they make it to the public. It enables switching all users over to a new release at once.
Benefits of Kubernetes:
Scalability: Kubernetes enables horizontal scaling of applications, allowing them to handle increased traffic and load. It can automatically scale the number of pods based on defined policies or metrics, ensuring optimal resource utilization.
High Availability: Kubernetes provides self-healing capabilities that automatically detect and replace failed containers or nodes, ensuring the availability of applications even in the presence of failures.
Portability: Kubernetes abstracts the underlying infrastructure, making it easy to deploy and manage applications across different cloud providers, on-premises data centers, or even on local development machines.
DevOps-friendly: Kubernetes promotes a DevOps culture by providing declarative configuration, versioning, and rollback capabilities. It also integrates with popular CI/CD tools, enabling automated application deployment and updates.
Basic K8 Commands
Description | Commands |
---|---|
Get information about pods | kubectl get pods |
Get information about services | kubectl get services |
Get information about deployments | kubectl get deployments |
Describe a specific pod | kubectl describe pod <pod_name> |
Describe a specific service | kubectl describe service <svc_name> |
Create a pod from a YAML file | kubectl create -f <pod_file.yaml> |
Create a service with specified parameters | kubectl create service <svc_name> |
Create or update a pod based on the YAML file | kubectl apply -f <pod_file.yaml> |
Delete a specific pod | kubectl delete pod <pod_name> |
Delete a specific service | kubectl delete service <svc_name> |
Edit the configuration of a specific pod | kubectl edit pod <pod_name> |
View logs of a specific pod | kubectl logs <pod_name> |
Kubernetes has become the de-facto standard for container orchestration, offering powerful features for deploying, scaling, and managing containerized applications. Its benefits of scalability, high availability, portability, and DevOps-friendliness make it a compelling choice for modern application development and deployment.