Kubernetes or K8s or Kube is an open-source container orchestration tool developed by Google. It can automate many processes involved in deploying, managing and scaling containerized applications.
Minikube implements a local K8s cluster which is useful for local K8s application development.
In this blog, I am going to introduce how to install Minikube and get started with it. Regarding the concept of the components of K8s, please refer to the official guide.
Installation
Based on the official guide, here are the requirements to install minikube.
2 CPUs or more
2GB of free memory
20GB of free disk space
Internet connection
Container or virtual machine manager, such as: Docker, QEMU, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation
My system is Mac OS and I have installed Docker. And here is my install script.
brew install minikube
minikube start --driver docker
# check the status of minikube
minikube status
Basic Kubectl Commands
To create the pods, we need to specify the blueprint for them. This is called deployment in K8s. The most basic configuration for deployment is the name and the image to use. For instance, we can create the nginx pods with the following command.
kubectl create deployment nginx-depl --image=nginx
# verify the pods, node and deployment
kubectl get pod
kubectl get node
kubectl get deployment
kubectl get replicaset
Several concepts here:
node is the minikube node
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes.
Replicaset is managing the replicas of a pod
Everything below Deployment is handled by Kubernetes. For instance, if we want to change the image version, we need to change the deployment with the following command.
kubectl edit deployment nginx-depl
If we want to debug the pod, we can use the following commands to check the logs.
kubectl describe pod {pod_name}
kubectl logs {pod_name}
# enter the container
kubectl exec -it {pod_name} -- bin/bash
Manage Deployment with Configuration File
We can use commands to handle simple cases. But when it comes to complex scenarios, we need to use the configuration file. Here is a YAML sample file: config-file.yaml.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.23
ports:
- containerPort: 80
Then we can use the commands to delete, create or update deployment.
# delete the deployment and it also deletes the relevant pods, replicaset
kubectl delete deployment nginx-depl
# use the configure file
# this can create or update the kubernete
kubectl apply -f config-file.yaml
Summary
In this blog, we show how to install minikube and tried several basic Kubectl commands.
Reference
Module 10 of DevOps Bootcamp