KUBERNETES TUTORIAL PART 2
IN The previous part i told you about Kubernetes and gave you little insight about pods and nodes if you want to view my previous blog you can follow this link : https://106northendblogs.blogspot.com/2019/05/break-all-rules-and-learnkubernetes.html
Before we start kubernetes we have to install Minikube which will run on your local system without the need of internet you can use minikube to create cluster , nodes ,pods
Before we start kubernetes we have to install Minikube which will run on your local system without the need of internet you can use minikube to create cluster , nodes ,pods
lets start shall we :
https://computingforgeeks.com/how-to-install-minikube-on-ubuntu-18-04/ ->for Ubuntu 18
https://kubernetes.io/docs/tasks/tools/install-minikube/
WHAT IS MINIKUBE ?
Minikube is ideal tool to setup kubernetes (k8s from now on) locally to test and experiment with your deployments.
MINIKUBE INSTALLATION ->https://computingforgeeks.com/how-to-install-minikube-on-ubuntu-18-04/ ->for Ubuntu 18
https://kubernetes.io/docs/tasks/tools/install-minikube/
In this blog we will cover all these topic -
- Pod creation / deletion
- Deployments
- Logging into the pods/containers
- Viewing logs of the pods/containers
A Pod (not container) is the basic building-block/worker-unit in Kubernetes. Normally a pod is a part of a Deployment.
We start by creating our first deployment. Normally people will run an nginx container/pod as
first example o deployment.
You can surely do that. But, we will run a different container image as our first exercise.
The reason is that it will work as a multitool for testing and debugging throughout this course.
Besides it too runs nginx!
first example o deployment.
You can surely do that. But, we will run a different container image as our first exercise.
The reason is that it will work as a multitool for testing and debugging throughout this course.
Besides it too runs nginx!
Here is the command to do it:
kubectl run multitool --image=<IMAGE NAME >
You should be able to see the following output:
$ kubectl run multitool --image=praqma/network-multitool
deployment "multitool" created
grafana/grafana
What this command does behind the scenes is, it creates a deployment named multitool, starts a pod using this docker image (praqma/network-multitool), and makes that 8787pod a memeber of that deployment. You don't need to confuse yourself with all these details at this stage. This is just extra (but vital) information. Just so you know what we are talking about, check the list of pods and deployments:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
multitool-3148954972-k8q06 1/1 Running 0 3m
There is actually also a replica set, which is created as a result of the run command above,
but we did not mention earlier;
because that is not super important to know at this point.
It is something which deals with the number of copies of this pod.
It will be covered in later exercise.
It is shown below just for the sake of completeness.
but we did not mention earlier;
because that is not super important to know at this point.
It is something which deals with the number of copies of this pod.
It will be covered in later exercise.
It is shown below just for the sake of completeness.
NAME DESIRED CURRENT READY AGE
multitool-3148954972 1 1 1 3m
The bottom line is that we wanted to have a pod running, and we have that. Lets set up another pod, a traditional nginx deployment, with a specific version - 1.7.9.
Set Up an nginx deployment with nginx:1.7.9
kubectl run nginx --image=nginx:1.7.9
You get another deployment and a replicaset as a result of above command, shown below,
so you know what to expect:
$ kubectl get pods,deployments,replicasets
NAME READY STATUS RESTARTS AGE
po/multitool-3148954972-k8q06 1/1 Running 0 25m
po/nginx-1480123054-xn5p8 1/1 Running 0 14s
so you know what to expect:
$ kubectl get pods,deployments,replicasets
NAME READY STATUS RESTARTS AGE
po/multitool-3148954972-k8q06 1/1 Running 0 25m
po/nginx-1480123054-xn5p8 1/1 Running 0 14s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/multitool 1 1 1 1 25m
deploy/nginx 1 1 1 1 14s
NAME DESIRED CURRENT READY AGE
rs/multitool-3148954972 1 1 1 25m
rs/nginx-1480123054 1 1 1 14s
The alternate/ preferred way to deploy pods:
You can also use the nginx-simple-deployment.yaml file to create the same nginx
deployment.
The file is in the suport-files directory of this repo. However before you execute the command shown below,
note that it will try to create a deployment with the name nginx.
If you already have a deployment named nginx running, as done in the previous step,
then you will need to delete that first.
deployment.
The file is in the suport-files directory of this repo. However before you execute the command shown below,
note that it will try to create a deployment with the name nginx.
If you already have a deployment named nginx running, as done in the previous step,
then you will need to delete that first.
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
multitool 1 1 1 1 32m
nginx 1 1 1 1 7m
$ kubectl delete deployment nginx
deployment "nginx" deleted
Now you are ready to proceed with the example below:
$ kubectl create -f <yaml-filename>
$ kubectl create -f nginx-simple-deployment.yaml
deployment "nginx" created
The contents of nginx-simple-deployment.yaml are as follow
$ cat <yaml-filename>
$ cat nginx-simple-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Verify that the deployment is created:
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 1 1 1 1 36s
Check if the pods are running:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-431080787-9r0lx 1/1 Running 0 40s
Exec into the pod/container:
Just like docker exec, you can exec into a kubernetes pod/container by using kubectl exec. This is a good way to troubleshoot any problems. All you need is the name of the pod (and container name - in case it is a multi-container pod).
You can exec into the pod like so:
$ kubectl exec -it <pod name> /bin/sh/ #
You can do a lot of troubleshooting after you exec (log) into the pod:
$ kubectl exec -it standalone-busybox-pod /bin/sh
Logs: You can also check logs of your pods by this command$ kubectl exec -it <pod name> /bin/sh/ #
You can do a lot of troubleshooting after you exec (log) into the pod:
$ kubectl exec -it standalone-busybox-pod /bin/sh
$ kubectl logs <pod name>
$ kubectl logs standalone-nginx-pod
If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook. Thank you!
Do you have any questions ?
please ask anything related to Pods Deployment,Replica sets,Pods logs,Minikube installation and anything related to Kubernetes in the comment section.
Next week I’ll post about How to do Loadbalancing on Nodes which is the most useful concept in kubernetes and some useful commmands which will help you in deploying service to kubernetes and after that i will give you some intro to Helm .
email: sudhanshu.techycardia@gmail.com
contact: 7006092013
Comments
Post a Comment