CKAD : 3. Build


App Container (appc) is an open specification that defines several aspects of how to run applications in containers: an image format, runtime environment, and discovery protocol. rkt's native image format and runtime environment are those defined by the specification.

clear container (from intel) uses kvmtool mini-hypervisor. So it is VM with quick bootup and low memory footprint. Not comparable with Docker but acceptable for many use cases. 

If we create a file inside Docker container, then it is acutally located at 
/var/snap/docker/common/var-lib-docker/aufs/diff/  
OR 
/var/lib/docker/aufs/diff/

Tools
1. Docker
2. buildah
- create OCI image
- with or without Dockerfile
- no superuser previliage needed
- Go-lan based API for easy integation
3. podman (pod manager)
- replacement of "docker run"
- it is for container LCM
4. Kompose

sudo kompose convert -f docker-compose.yaml -o localregistry.yaml

latest is just a string. we need process to name and rename latest version as "laters" as an when it available. Else, there is no point. 

k exec -it -- /bin/bash
Here instead of /bin/bash any tool of local host, (where kubectl is running) can be used. 

redinessProbe and livenessProbe
1. exec statement
2. HTTP GET. return value 200-399
3. TCP. Try to open port on pre-determined port

To get logs generated by etcd
k -n kube-system logs etcd

The events can be listed with
k describe pod  

We can user "--dry-run -o yaml" just to generate YAML file

Minikube

To access K8s service on Minikube we have few approaches

1. Make it as NodePort Service

1.1  we can change service type as NodePort by
k path svc -p '{"spec":{"type":"NodePort"}}'
Now to access NodePort service on Minikube, we need IP address of virtual box. 

1.2
minikube ip
this command  give IP address of Worker+Master Node.
User command 
curl http://192.168.99.108:31754/v2/
curl http://"Minikube IP":"NodePort"/v2/

1.3

Use the command
minikube service --url
you will get service end point
http://192.168.99.108:31754

http://"Minikube IP":"NodePort"

We can open this URL using default browser using command
minikube service 

2.1

We can use ClusterIP

sudo route add 10.100.88.2 gw 192.168.99.108
sudo route add gw

Registry

We should add insecure registry to docker with its ClusterIP 

sudo vim /etc/docker/daemon.json

{ "insecure-registries":["10.110.186.162:5000"] }

Then Restart Docker Service
sudo systemctl restart docker.service

CKAD : 2. K8s Architecture


Key take away points
  • All the configuration is defined in YAML and stored in JSON format
  • Container creation tools: Buildah, Podman, cri-o, containerd, frakti, 
  • Mesos has multi level scheduler for data center cluster
  • Evolution: Brog-> Mesos, Cloud Foundry, K8s, Omega
  • Replication Controller is now
  • - Deployment controller
  • - Replicaset
  • ReplicaSet has Selector, 
  • ReplicationController does not have Selector
  • If we edit rs, then it is applicable only for new pods
  • To get details about container image "k describe pod | rs" is better command
  • rs has metaData - > name So if we rs is part of deploy. If we delete rs, then new rs is created with same name. If rs is not part of deploy then first we need to store it by "k get rs 'rs name' - o yaml > 'file name' " then create it again with command "k create -f 'file name'"
  • If pod is part of rs OR if pod is part of deploy (so it is part of rs too). If we delete pod, then it will create with new name, because pod has metaData -> generateName
  • Deployment ensures that resources are available such as (1) IP Address and (2) Storage. Then deploys ReplicaSet
  • So if we delete ReplicaSet then deployment recreate it. 
  • If we delete deployment, then ReplicSet also get deleted. But service and pod remains
  • If we delete service then pod does not get deleted.
  • Annotation is not for k8s. it is for 3rd party tools
  • 'Cloud controller manager' is optional at master node. If it is present, the kublet shall be started with option --cloud-provider-external
  • Pause container is used to get IP address
  • We can edit only few fields of pod (1) image (2) activeDeadlineSeconds (3) tolerations. However if we edit deploy, we edit any param and pod will be automatically restarted. 
Tent and Tolerations
  • Node has taints to discourage pod assignment, unless pod has toleration taint is expressed as key=value:effect There are 3 effects. (1) No Schedule (2) Prefer No Schedule (3) No Execute means existing pod will be evacuated. 
  • Master node will have taint : No Schedule 
  • To create taint the command is : k taint nodes 'node name' key=value:effect
  • To remove the taint the commands are: k taint nodes 'node name' key=value:effect- , k taint nodes 'node name' key- & k taint nodes 'node name' key:effect-
  • Pod has tolerations = "key", operator ("Equal"), "value", "effect" (same as above)
  • We can edit pod's tolerations with k edit command.
  • If tolerations operator = Exists then only key + effect shall match. 
  • If tolerations operator = Equal (default value is Equal) then only key + value + effect shall match. 
  • Taints and tolerations is not about which pod will get schedule on which node. It only tells node that given pod can be accepted or not. 
Node Affinity
  • To schedule a pod on specific node we have node affinity. 
Dockerfile and pod relation
  • With Docker command whatever additional parameter we pass, that will be replaced CMD and append to ENTRYPOINT of Dockerfile
  • Docker command can replace ENTRYPOINT also with --entrypoint option. 
  • Dockerfile ## Docker Command ## Pod YAML
  • ENTRYPOINT ## --entrypoint ## command:
  • CMD ##  ## args:


Useful commands



To use any command in different namespace
(1) kubectl (2) verb (3) -n 'namespace name' (4) then rest of the part of command. 
We cannot add 
-n 'namespace name'
at the end of command

1. 
A. To run pod, without YAML file 

k run newpod --image=nginx --generator=run-pod/v1

k run newpod --image=nginx --dry-run --restart=Never -o yaml

Here the pod name and container name will be identical

We can specify label with "-l key=value"

B. To create deployment without YAML file 

k run firstpod --image=nginx

k run firstpod --image=nginx --dry-run -o yaml

k create deployment firstpod --image=nginx
k create deployment firstpod --image=nginx --dry-run -o yaml

We shall mention container port in deployment

        ports:

        - containerPort: 3306


C. To create service. if pod has label app=svcname. We cannot pass label name to svc

kubectl expose pod pod_name --port=6379 --name svcname --dry-run -o yaml

kubectl create service clusterip svcname --tcp=6379:6379 --dry-run -o yaml

kubectl create service nodeport svcname --tcp=6379:6379 --node-port=32080 --dry-run -o yaml

If we do not have any pod with label app=svcname then also service will be created. However when we list ep, we found there is no pod in that svc

2. To know all taints k describe nodes | grep -i taint

3.1 To know about all resources k api-resources

Here are list of shortcuts

ConfigMap ---- cm
EndPoints ----- ep
Namespace --- ns
Node --------    no
PersistentVolumeClaim --- pvc
PersistentVolume --- pv
Pod -- po
ReplicationController -- rc
ServiceAccount --- sa
Service --- svc
CustomResourceDefinition --- crd
DaemonSet --- ds
Deployment --- deploy
ReplicaSet --- rs
StatefulSet --- sts
HorizontalPodAutoscaler --- hpa
CronJob --- cj
CertificateSigningRequest --- csr
Ingress --- ing
NetworkPolicy --- netpol
PodSecurityPolicy --- psp
StorageClass --- sc

3.2 We can list associated verbs with command k api-resources -o wide

3.3 We can list multiple resources as comma separated list
kubectl get deploy,rs,po,svc,ep

4. Under container we write:
ports:
- containerPort: 80

5. Under Service we write:
ports:
 - protocol: TCP
   port: 80


6. Useful commands tips

Context
Create context
k config set-context "any context name"  --namespace='name space name'

context is (1) cluster (2) namespace and (3) user

List context
k config get-contexts

Use specific context
k config use-context 'context name'


k explain 

Please refer for imperative commands : https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

We should use grep command with "-C number" option. 
C for number of line before and after both
B for before
A for after

Kubernetes Resource Map


Docker image, without Internet


Let's assume, you wish to run a K8s pod with Docker container on a host, where there is no Internet. This blog will describe steps 

Run below command on another host, where Internet connection is present. 

docker save -o /

Then transfer to target host using FTP or SCP

At target host, run following command

docker load -i

Now make sure, at YAML file for pod or deployment, you add below line

imagePullPolicy: IfNotPresent

2019: Looking back with smile


Happy New Year 2020

For last two years, I reflect upon my life, achievements for previous year. So here was my year 2019

Spiritual/Religious: 

  • Attended satsang with Sri Sri Ravishankar Guruji. 
  • Read His commentary on "Shrimad Bhagavad Gita", in a WhatsApp group. Effectively utilization of WhatsApp and free time, whenever I need to wait for anyone. 
  • Attended Advance Mediation silence course for the 7th time

Social Media:

  • Now this blog is super active. Maximum posts 73 in this year. Majority are technical
  • Completed a series of online courses under "DevOps for Practitioners". Good refreshment of quality principal, that we learnt during MBA. Also happy to know, how they are applied in today's IT industry. 
  • Tried LinkedIn Premium 
  • GitHub: 
  • Earlier I created category "Bookmark" on this blog. Now it is no longer valid. Technology is changing so far. Many technical posts, I am keep updating. 

Learning:

Registered for Certified Kubernetes Application Developer (CKAD) exam.  
Attended many technical events, including Kubernetes Day India

Sanskrit Promotion: 

  • Conducted 6th free workshop about Spoken Sanskrit in Feb 2019
  • Encouraged school students for Sanskrit by solving their doubts.
  • Continued watching YouTube series by Dr. Baladevanand Sagar on topic "Learn Sanskrit, Be Modern !". 

Professional:
  • After almost 10 years, I changed job. Here also, learning new technology and here also, working with best talented people of our industry. 
  • Reconnected and had nice, meaningful conversion with old colleagues and professional people. 
  • Continue making new friends using Quick Ride
Book

I read an excellent book. Transcendence. Read my book review here. I also read another interesting book "The Phoenix Project". It is a business novel with ToC (Theory of Constraint) principle for DevOps. 

Entertainment: 

  • Watched few movies:
    • Helaro Gujarati movie was good. 
    • Mission Mangal Hindi movie was the best
  • Watched a documentary movie on 
    • Indian Airforce
    • NaMo's "wild v/s man"

Next Year 2020:
  • Spend more time with people, famly, friends. 
  • Regular in SAADHANA
  • Complete YouTube series by Dr. Baladevanand Sagar on topic "Learn Sanskrit, Be Modern !". 
  • Re-Start conducting Free Spoken Sanskrit classes. 
  • Continue enriching my personal blog. A new series will be started about my personal notes on  "Machine Learning" course at coursera by Andrew NG. 
  • Clean up all old Bookmarks in Google Chrome. 
  • Cultivate good habits and get rid of bad habits. 
You may also like: 

2018: Looking back with smile
2017: Looking back with smile