Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate deploying, scaling, and operating application containers. It provides a framework to run distributed systems resiliently, handling the scaling and failover for your applications, and provides deployment patterns.
A Kubernetes cluster consists of a set of nodes that run containerized applications. A cluster has at least one master node and multiple worker nodes.
A node is a worker machine in Kubernetes, which can be either a physical or virtual machine. Each node runs pods, which are the smallest deployable units in Kubernetes.
A pod is a group of one or more containers, with shared storage/network resources, and a specification for how to run the containers. Pods are the basic unit of scaling in Kubernetes.
A service is an abstraction that defines a logical set of pods and a policy by which to access them. This can be used to expose the application running in the pods to the outside world.
A deployment is a higher-level concept that manages the creation and scaling of pods. It ensures that a specified number of pod replicas are running at any given time.
To get started with Kubernetes, you can use Minikube, which creates a local Kubernetes cluster on your machine. Here’s how to set it up:
You can install Minikube using the following command:
# For macOS
brew install minikube
# For Ubuntu
sudo apt-get update
sudo apt-get install -y apt-transport-https && \
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && \
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Once installed, you can start your Minikube cluster with:
minikube start
To check if your cluster is up and running, use:
kubectl get nodes
Let's create a simple deployment to run a Nginx web server.
You can create a deployment using the following command:
kubectl create deployment nginx --image=nginx
To expose the deployment to the outside world, run:
kubectl expose deployment nginx --type=NodePort --port=80
You can access your application with:
minikube service nginx
Always define resource requests and limits for your containers to ensure that your application has enough resources to run efficiently.
Use labels and annotations wisely to organize and manage your Kubernetes resources.
minikube start.bash
kubectl create deployment redis --image=redisbash
kubectl scale deployment nginx --replicas=3bash
kubectl get podsbash
kubectl delete deployment nginx
kubectl delete service nginx