General · Kubernetes · Linux · MAC

Kubernetes LittleSchool

Statement : Kubernetes is an open-source container-orchestration system for automating application deployment, scaling, and management. It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.

Prerequisites : Though we have multiple vendors like Azure, AWS, CloudStack etc to setup kubernetes cluster in cloud but first we want to set it up on our local machine.

  • Install kubectl
brew install kubectl
kubectl version
  • Install MiniKube
# Please make sure you have virtual box installed on your machine.
brew install minikube
minikube version
# Start Minikube to create a kubernetes cluster
minikube start
# To stop a kubernetes cluster
minikube stop
# To check the Kubernetes CLuster Status whether it is running or not.
minikube status
# To check the Kubernetes Standard UI
minikube dashboard
# To delete a kubernetes cluster
minikube delete

Kubernetes Fundamentals :

First of all, we must understand the basic terminology of Kubernetes. In this, we would be using some of following terms very frequently –

  • kubectl : It is command line interface which helps us to communicate with kubernetes control plane (kubernetes master). The Kubernetes master is responsible for maintaining the desired state for your cluster.
  • Kube API : Kube API in the control plane takes care of all the commands issued by kubectl and in turn performs the CRUD operation against API objects.
  • Pod : Pod is the smallest unit in the context of Kubernetes. It could be the combination of one or more docker containers.
  • Node : Node is nothing but a physical or virtual machine which contains multiple pods in Kubernetes.
  • Scheduler : As name indicates, scheduler in the control plane helps pod to schedule and assign them to some node to run and the same information is sent back and forth to Kube API.
  • Controller : Controllers (Node, Replication, Endpoints controller etc ) in the control plane takes care of all the events happening through Kube APIs and respond them accordingly. Ultimately they control the scheduler.
  • Kube Porxy : This helps to create ip tables and provide access to the pods inside the cluster when any service or end point is created in the node. On the other hand, Kube DNS helps us to detect the service or end point created inside the cluster and then expose the service outside of the cluster.
  • Namespace : Namespace is the logical way to club multiple nodes together to divide cluster resources between multiple users.
  • ReplicaSet : By default, Pods are not fault tolerant and in turn ReplicaSets takes care of making the same number of pods in terms of it’s replica and makes pods scalable.
  • Ingress : Ingress takes care of forwarding the traffic and allows us to access the application running inside a node.
  • Volume : To make a system stateful Volume plays a vital role in Kubernetes and in turn saves the state of the container in case it is restarted or crashed.
  • Config Maps : A ConfigMap is an API object used to store non-confidential data in key-value pairs. 
  • Secrets : All the confidential data is stored inside secrets.
# To Create a Pod, Replica Set, Service, Deployment, Ingress, Config Map, Secret or Namespace.
kubectl create pod/rs/service/deployment/ingress/cm/secret/ns
# To Get all Pods, Replica Set, Ingress, Nodes, Persistent Volumes, Storage Class, Roles, Cluster Roles or Namespace.
kubectl get pods/rs/ing/nodes/pv/sc/roles/clusterroles/ns
# TO get everything as a part of specific Namespace.
kubectl --namespace <namespace_name> get all
# TO get everything
kubectl get all
# Execute a Pod having with specific image
kubectl run Pod_Name --image Image_Name
# To get the details of a particular pod
kubectl describe pod Pod_Name
# Enter into the  specific pod by executing bash command inside.
kubectl exec -it Pod_Name bash
# TO get the logs of a specific pod.
kubectl logs Pod_Name
# To delete a specific pod.
kubectl delete pod Pod_Name
# TO make any changes or to update any resource
kubectl apply
# To know the current context in terms of selected cluster.
kubectl config current-context
# To use the specific context in terms of selecting the cluster.
kubectl config use-context minikube
# To get all the clusters contexts
kubectl config get-contexts
# to expose a resource as a new Kubernetes Service.
kubectl expose
# Rolling Back to a Previous Revision.
kubectl rollout undo deployment
# Rolling Back to a specific Revision.
kubectl rollout undo deployment --to-revision=2
# Get the history of all the deployment
kubectl rollout history deployment
# To see the Deployment rollout status
kubectl rollout status deployment
# Set the image and record/save the annotation.
kubectl set image image_name --record

Now, you have the basic knowledge of Kubernetes and using the above commands you can perform your daily stuff if you are involved in any of projects which uses Kubernetes. Keep playing and I hope you would have enjoyed in Kube LittleSchool 🙂