After writing about Docker, I am going to share about the Kubernetes(k8s). Kubernetes is built on Docker technology. This article mainly explains the Kubernetes architecture, key concepts and how to use Kubernetes.
What is Kubernetes?
Kubernete is open source container management system where you can deploy application containers across clusters of hosts.It provides container centric infrastructure.An important feature of kubernete is can actively manage the container and ensure the continued status of the cluster. It also allows maximizing the use of hardware resources.
Kubernete is mainly for the system admin to deploy the code.Kubernetes has fifteen years of experience in running large-scale container cluster and the important part is also supported Docker containers.
Let’s understand the features of Kubernetes:
- You can quickly deploy the application.
- You can scale the application.
- Rolling updates
Kubernetes is a physical and virtual machine. Many Big companies like Google, Red hat, Intel, Puppet, CoreOS etc are using the Kubernete.
Basic Components of Kubernetes
Let’s begin with the basic components of the Kubernete.
Kubectl is a command to controls the Kubernetes cluster manager. Kubectl provides many options which you learn from here (http://kubernetes.io/docs/user-guide/kubectl/kubectl/ )
Key Concepts of Kubernetes:
- Persistent Volumes
Kubernetes is the most basic deployment scheduling unit where you can create Pods.The pod is a set the container with a shared disk.The pod can be created individually.
Docker file is supposed to create docker image but here You will use the existing docker images to deploy the things.Pod is a group of containers.The pod is used to solve the problem of expansion and volume reduction.
Some more important things about Pods
- Smallest deployable units that can be created and managed in k8s
- Share resources like volumes, IP address
- Group of containers scheduled on the same host
- Can also communicate using standard IPC
- Containers within a pod can find each other via localhost
- Containers in different pods have distinct IP addresses and can not communicate by IPC.
The following example will create a Pod
apiVersion: v1 kind: Pod metadata: name: nginx spec: Containers: - Name: nginx-server image: nginx ports: - ContainerPort: 80
In this,Name is the name of the container and image Is the name of the image that will be used Docker mirror.containerPort is the port of the container to communicate with the IP address Pod Nginx server.Metadata is the data.
Once the pod is created, you can list them to see what is up and running using the following command:
kubectl get pods
Kubernetes has the features of rolling updates that make the deployment process for administrator very simple. Labels are the very important part for that. There are commands for specifically do deployments and rolling updates where you can distinguish using appropriate labels.
Labels is an inbuilt feature in kubernetes. They have key value pairs where you can attach to the objects.It is not limited to Pods, you can attach replication controllers,servers etc almost anything.
Labels are used to make sure the management of an object is simple.If you are using VMware, you might have come across the concept of tags so this is just the different name for those tags.
- Key/Value pairs that are attached to objects, such as pods
- This is used to organize and select subsets of objects
- Example of labels are very simple:
- “release” : “stable”, “release” : “canary”
- “environment” : “dev”, “environment” : “qa”, “environment” : “production”
Here is the example of labels in kubernete
apiVersion: V1 #api version number kind: Pod # define resource types Metadata: # define the resource attribute information name: nginx labels: # define labels App: Nginx # define key / value pair : spec details #define Resources containers: - Name: nginx Image:nginx-image ports: - ContainerPort: 80
Replication Controllers (rc)
Support your all pods are working on the single system so imagine that system is going down so run environment screwed. In that case, you need to have replication and that is what replication controller come into the picture.
Replication Controllers is made sure that specific replicas exist.If you need more replicas and only one pod are running currently,so it will spin up some new pods for you.The reverse is also true if you have modified YAML file and if you change it again to one, it will kill all other or unused pods.
When you create Replication Controllers using YAML, you will get the selector field. Selector will decide which pods going to replicate.
Let’s have an example, There are 5 replicas exists, and you get more traffic and you want to increase the replicas, you can just increase on the fly without any downtime.
Here is the main points of Replication Controllers
- Ensures a specified number of pod “replicas” are running
- Manages all the pods with labels which match the “selector”
- If there are more pods, it will kill some
- If there are less pods, it will start more
- Increase/Decrease number of replicas on the fly
Now, let’s create the Replication Controller
apiVersion: v1 kind: ReplicationController metadata: name: nginx-controller spec: replicas: 2 Number # 2 is defined as running pod Selector: # define tag selector for the app = nginx app: nginx Template: (a method similar to the definition of pod, pod explanation see above) # rc-defined templates metadata: labels: app: nginx spec: containers: - Name: nginx Image: 10.20.161.77:5000 / Nginx ports: - ContainerPort: 80
Services have an own purpose,Pod IP addresses cannot be relied upon because pods can come up and go down anytime.
What if pods (backend) provide some service to other pods (frontend) and backend pods suddenly die? So Kubernete will make sure new pods created immediately but what about IP address so application might be stopped and that is the scenario where services come into the picture.
Services look up at the IP address so when you call the specific IP address, it will send the request to any available backend pods. For example, You have 5 replicas so it will send the request to any of replica from five replicas
Again you are going to use the selector freed YAML file so that kind of the same concept we saw in the Replication Controller.Services define logical set of Pods and Set of Pods targeted by a Service is determined by “selector”
Service has one logical IP address means it has the single point of an area so that’s why skyDNS comes into the picture.skyDNS gives the DNS functionality so instead of IP address you have DNS name.If one your services are skying and it have different pods or nods,there might be the case that it’s IP address changed but DNS name is same.You can just rely on it.
Here to try to establish a service Kubernete.
Nginxsvc.yaml create a file and write to:
apiVersion: v1 kind: Service metadata: name: nginxsvc labels: app: nginx spec: the ports: - Port: 80 protocol: TCP selector: app: nginx
Deployments are useful to create Pods and Replica Sets in one node.Replica Sets is the next gen Replication Controller. Deployments provide declarative updates for Pods and Replica Sets (next gen RC).It is used to bring up Pods and Replica Sets and also for Canary deployments
Volumes are just another directory accessible to the Pod.The moment when Pods getting killed, the have volume is killed too.Volumes get mounted at specific path within image or container.
Some other useful points of volumes.
- Ceases to exist when Pod ceases to exist
- Support for many volume types; Pod can use any number of them simultaneously
- Mounted at the specified paths within the image
Volume Types supported are listed below:
- rbd (Ceph) – Object Storage.
Persistent Volume has life cycle going to extend on the Pods. If in case, Your Pod is dead, the Persistent Volume still exists. Persistent Volume created by the administrator.Persistent Volume is a piece of networked storage in the cluster provisioned by an administrator.It is lifecycle independent of any individual pod that uses the PV.
Here is the types Persistent Volume:
- RBD (Ceph)
What are the advantages of Kubernetes?
- First advantage is Kubernete is lightweight and very simple to understand so can anybody use it.
- Kubernete provides public,private and hybrid cloud deployment so it is portable.
- Using kubernete, you can have automatically deployment,restart and copy which reduces maintenance work.
- Kubernete is pluggable and modular technology so you can attach it anywhere.
I hope you will have a better understanding of the Kubernetes.Enjoyed reading this article? Do share this article with your friends on Facebook & Twitter.Feel free to share your thoughts and comments below.