kubernetes
Class 001
What is Kubernetes?
- Kubernetes is an Orchestration engine and open-Source Platform for managing containerized applications.
- Responsibilities includes Container Deployment, Scaling & descaling of container & Container load balancing.
- Kubernetes is not a replacement for Docker.
- Kubernetes can be considered as a replacement for docker swam.
- Kubernetes is significantly more complex than Swarm.
- Born in Google, written in Go/Golan. Donate to CNCF (Cloud Native Computing Foundation) in 2014.
- Kubernetes V1.0 was released on JULY 21, 2015.
- Current stable release v1.27
Kubernetes Features:
- Automated Scheduling.
- Self-Healing Capabilities.
- Automated rollout & rollback -------------------------- (Releasing a new version/Previous version).
- Horizontal Scaling & Load balancing.
- Autoscaling of PODS (Containers)
- Manual
- Service Discovered & Load balancing. (DNS)
- Storage Orchestration.
Kubernetes Architecture:
- Kubernetes implements a cluster computing background, everything works from inside a Kubernetes cluster.
- Cluster means (a group of nodes).
- The cluster is hosted by on node acting as the “Master-node”,
- The other nodes as a “worker-nodes”.
- .
- In the real world 3 Master node is recommended, for fault tolerance.
- The master node is responsible for the management of kubernetes cluster.
- It is mainly the entry point for all the administrative tasks.
- Responsible for scheduling the container.
- Deploying the container.
- After deployment (looking after those nodes).
- Responsible for re-scheduling the container.
- Responsible for re-creating the container.
- API Server
- Schedular
- Control-Manager
- ETCD
What is API Server?
- Application programming Interface.
- Kubernetes API Server will interactive with API,
- It’s a frontend of the kubernetes control plane.
- Whatever you want do in kubernetes like
- Creating POD
- Delating a POD
- Creating deployment / Delating a deployment.
- For that we need to call an API’s.
- Kubernetes CLI using kubectl, we can communicate with k8s cluster (API Servers).
What is ETCD?
- ETCD is a kind of database.
- It can be maintainer kubernetes information (state).
- It store all cluster data’s,
- Scheduling information, pods, state information.
- Kubelet
- Kube-proxy
Kubelet:
- Kubelet is the primary node agent,
- It will runs on each nodes and reads the container manifests which ensure that containers are running and healthy.
- It makes that containers are running in a POD.
- A pod is collection of one or more container.
- I kubernetes we are creating a PODs.
- The PODs will have a containers (one or more container).
- Containers wrapped under the PODs.
- Kubernetes deprecated docker
Class 002
- Kubernetes also called as k8s.
- We can install k8s in anywhere (on perm, online, VMware …etc.,)
Types of K8s:
- Self-managed / Bare Metal k8s cluster.
- We need to setup the cluster and managed the k8s cluster.
- Miniqube --------------------Single node k8s Cluster
- Kubeadm---------------------Using kubeadm we can provision (setup) multi k8s cluster. * * * *
- kubespray
- Managed k8s cluster.
- EKS
- AKS
- GKE
- IKE ------------------------IBM Kubernetes Engine
Installation:
- Control plane / Master node
- Worker node
Ports need to open:
·
Master node / control-plane node
- 6443 Kubernetes API Server
- 2379-2380 etcd server client API
- 10250 Kubelet API
- 10251 kube-Scheduler
- 10252 kube-controller-manager
· Worker node
- 10250 Kubelet API
- 30000-32767 Node Port Services (nothing but host port)
- .
- kubectl version
- kubectl get nodes
- kubectl get nodes -n kube-system
- kubectl get nodes -n kube-system -o wide
- kubectl cluster-info
- If you want to operate from other machine (like jenkins server)
- go to that server
- create directory ----------(mkdir ~/.kube)
- vi ~/.kube/config
- Copy config information from master and past it here.
- PODS
- Services
- ReplicationControllers
- ReplicaSets
- DeamonSets
- Deployments
- PeristanetVolumes
- PeristanetVolumesClaims
- StatefullSets
- Role
- ClusterRole
- RoleBinding
- ClusterRoleBinding
- .
- K8s will manage the containers, not directly.
- K8s will not create the containers directly.
- Containers are wrapped under one unit called POD in K8s.
- Namespace is a cluster inside the cluster.
- Virtual cluster inside your k8s cluster.
- We can create / deploy a group of related applications into a namespaces.
- We are logincally grouping /placing.
- Logically isolated from each other.
- The k8s resources into a namespaces
- .
- Kubectl get namespaces
- kubectl get ns
- kubeclt get pods -n kube-system
- kubeclt get all -n kube-system
- kubectl get pods
- kubeclt get all
- kubectl create namespace <New_Space_Name> (flipkartapp)
- If we delete namespace what are under that namespaces those resoureces also deleted.
- A Pod always runs on a Node.
- A Pod is the smallest building block or basic unit of Scheduling in K8s.
- which we can deploy a in k8s cluster.
- In a K8s cluster, a Pod represents a running process.
- K8s will create a PODs.
- A Pod will have one or more containers.
- Those containers all share a unique network IP,
- storage,
- network and any specification applied to the pod.
- Each Pod has its unique IP address within the cluster.
- kubectl apply -f <Mainfest_file>.yml
- kubectl get pods
- kubectl get events
- kubectl describe pod <Pod_name>
- kubectl describe <Object> <Object_name>
- kubectl get pods -o wide
- Containers to container communication within the pod.
- Since both are in the same network namespace.
- Yes
- we can mount data inside the pod.
- Both containers can able to access the storage device inside the pod.
- We can access the with in the cluster with help of Pod IP.
- go to the Master node / worker node ----(Because of these are the part of cluster.)
- curl <Pod_IP>:8080
- It in not recomended way to Pod IP communicate within the cluster one application to another application.
- Pod ip may change in future (continer delete, change).
- .
- If application has multiple pods (replicas), we may need a load balancer. so that is way k8s servicer come in to pitcure.
- Make a pod request to API server using a local pod (lubectl) (cli) defination file.
- The API server save the information for the pod in ETCD.
- The schedular finds the un-scheduled pods and schedule in to node.
- Kubelet running on node, seens the pod scheduled and fires up docker.
- Docker run the container.
- Ther entair lifecycle state of the pod is stored in ETCD.
- One-Container-per-pod
- Multi-Contaier-pod (or) Sidecar Container
- You need some healper for main processer.
- There the developer can split into a two processer.
- One procer can download the data from the external device/ sources, and keep it available for your main processer via volume.
- Second processer (Main processer) can read the volume and insert into the database.
- Service is for communication.
- Service makes Pod accessable / discoverable within the network or outside the network.
- Within the network (Cluster).
- Outside the network (Internet).
- When we create a service we will get one virtual IP address (Cluster IP address).
- This IP will be registed in k8s dns with it's name (Service name).
- So other applications can communicat using service name.
- Service will identify the Pods based on it's labels & selectors.
- kubeclt get pods --show-labels
- Types of services in k8s:
- Cluster IP service
- Node Port service
- Load Balancer service
- Heldless Service
- Cluster IP Service:
- Cluster IP Service exposes the service on a cluster-internal IP.
- Service in only reachable with in the cluster.
- This is default type.
- When we create a service we will get one Virtual IP (Cluster IP),it will get registerd to the DNS ( kube-DNS).
- Using this other pods can find and talk the pods of this service using "Service name".
- Service is just a logical concept, the real work is being done by the "kube-proxy" pod that is running on each node.
- It redirect request from cluster IP (Virtual IP Address) to pod IP.
- .
- kubeclt get svc
- kubectl describe service
- kubectl describe svc <Service_name>
- Nodeport is a service type in kubernetes.
- When we create a service type of "nodeport",we can access that application from outside using that port.
- .
- Since the Nodeport (kube-proxy )is opened in all servers.
- All servers in same cluster, thats why can able to access the outside of the world.
- With help of <public IP: portnumber>
- port number will created automatically form the range (30,000 -32,767)
- before creata a NodePort service check what are the ports are listing.
- sudo netstat -tulnp
- Pod is ephemeral (Lasting for very short time) and won't be rescheduled to a new node once it dies.
- You should not directly create/use pod for deployment,
- Kubernetes have controllers like
- Replication Controller
- Replica Sets,
- Deployment,
- Deamon sets to keep pod live.
- kubectl get rc
- kubectl get rs
- kubectl get ds
- kubectl get deployment
- Static pods are managed direclty by th kubelet.
- API server does not have any control over these pods.
- The kubelet is responsible to watch each static pod and restart if it is crashes/shutdown.
- The static pods are running on a nodes are visible on the API server but cannot be controlled by the API server.
- Static pods does not have any associated replication controller (ds, rc, rs, deployment),kubelet service itself watches and restart it when it crashes/shutdown.
- There is no health check for static pods.
- .
- The main use for static pods is to self-hosted contral plane.
- .
- If you want to creat a your own static pod?
- Yes we can create
- where ever you want to static pod (mastet/worker)
- you need to keep the pod manifest in below mention direcotory.
- /etc/kubernets/manifests/
- kubectl get pods -n kube-system
- kubectl get ds -n kube-systme
- kubectl get deployment -n kube-system
- kubectl get all -n kube-system
- Replication Controller is one of the key features of kubernetes,
- Which is responsible for managing the pod lifecycle.
- it is responsible for making sure that the specified number of pod replicas are running at any point of time.
- A Replication Controller is a structure that enable you to easily create multiple pods,
- than make sure that the number of pods always exist.
- If pod does crash/shutdown, the Replication Controller replaces it.
- Replication Controller and pods are assiocated with labels.
- Creating "RC" with count 1 ensure that a POD is always available.
- We created the RC. That RC will manage the pod lifecycle.
- RC will manage the pod.
- To access the pod, we have service.
- Service will have selector, the selector is nothing but labels.
- we can access within the cluster using service name or cluster ip with service port.
- For outside we can access with NodePort and node ip (Master node/ worker node) wih in the cluster.
- labels and selectors are very important.
- In k8s cluster one object find another object by using labels and selectors.
- labels are key value pairs.
selectors:
- If you give some image and tag. does't exist.
- it will try to pull the image from artifactory.
- if image / tag not available it will give the error "ErrImagePull"
- labels and selectors are very important.
- In k8s cluster one object find another object by using labels and selectors.
- labels are key value pairs.
- kubectl edit svc <SVC_Name>
- kubectl describe pod
- kubectl describe svc
- kubectl describe rs
- kubectl describe rc
- kubectl exec POD -- ls
- kubectl exec POD -- pwd
- kubeclt exec -it <pod_name> /bin/bash
- kubectl exec <Pod_name> -c <Container_name> -- pwd
- for log
- for cp
- kubectl logs <Pod_name>
- In Deemon Set each and every node will have copy of that POD.
- The Daemon Set like a Global mode in kubernetes.
- We can not scale up ad scale down in Daemon Set, each and every node will have a copy of that pod.
- What type of applications we can deploy as a Daemon Set?
- Any Software which is required to run in each and every node.
- internal softwares like
- Moniroting agents.
- log agents (kibena, ELK)
- Promothes (Node exportor)
- Our application like out own applications.
- Kubectl apply
- kubectl create -f
- kubectl update
- kubectl delete
- kubectl delete all --all
- All the cluster information like nodes,pods,deployment, ReplicationController,Replica Set.
- Stored in ETCD.
- If you want to deployment th application, which one you choose the deployment?
- ReplicationController
- ReplicaSet
- Deployment
- Deployment is recomended way Deployment applications.
- Beacause we update the deployment and rollback the deployment.
- Why we recomended Deployment is way to Deployment applications.
- In RC and RS
- In RC and RS if we want to update in manifest files that information will not update.
- it will process the old version only.
- if you want to update you need to delete RS and RC, again recreated.
- we can't achive zero down time.
- we can't rollback also, because we will not maintain version in k8s.
- Deployment will creata a Replica Set, while creating Deployment.
- The PODs are not re-created when ever changing in image for RS and RC.
- When we choose type "Recreate".
- Whatever created the Pods it will be deleted and recreated automcatically.
- will have a down time for "Recreate"
- Deployment will creata a Replica Set automatically, when we create Deployment type= Recreate.
- Deployment will create RC. RC will manage the pods.
- kubectl apply -f <Deployment_name.yaml> --record=true
- kubectl rollout history deployment <deployment _name>
- it is maintained old pod information also.
- kubectl rollout undo deployment <Deployment_name> --to-revision 1
.kube/config file has 3 sections:
- Cluster information
- Context
- Users
Create a Kubectl Client:
·
Go to Master Node
o
Sudo cat /etc/kubernetes/admin.conf (Copy data)
·
.
·
.
·
Install kubectl (on separate serve like… Jenkins )
· kubectl version - - client (Curl & install (options 1 3 4))
·
Go to personal laptop
o
mkdir ~/.kube ---------Ubuntu
o
Create a .kube ---------Windows
o
Vi config
·
Kubectl get nodes
·
curl –v
telnet://container_IP:Port (From kubectl server)
·
curl –v telnet://container_IP:Port (From Master server)
Namespace: Name
Space
·
Logical
grouping of your k8s cluster.
·
· Logically isolated from each other.
We
have a 4 types of Namespaces.
§ Default
§ Kube-system
§ Kube-
public
§ Kube-node-lease
We
can set the resource quota for the namespaces.
·
kubectl get namespaces
·
kubectl get ns
·
.
·
kubectl get all
·
kubectl get all
- n kube-system
·
kubectl get all - -
namespaces kube-system
Create a namespace:
Kubectl
create namespace <ns_name>
·
Create/Update/Read/Delete any k8s
Resources/Objects we use Kubectl (CLI).
·
We can in Two ways
1.
Imperative Approach
§
Using Commands
§
Kubectl get
nodes
§
Kubectl get all
§
Kubectl get - - namespaces
§
kubectl version --short
2.
Declarative Approach
§
We can Declare and then Create/Update/Read/Delete
in the form of file (manifest files).
§
yaml files
§
In manifest files we have below mentions artibutes
have.
·
apiversion:
·
kind:
·
metadata:
·
spec:
Declarative Way:
Create a namespace:
apiVersion: v1
kind: Namespace
metadata:
name: test-ns
labels:
team_name:
For_Testing
·
Kubectl apply - f <Filename. Yaml>
·
Kubectl create - f <Filename. Yaml>
·
.
·
Kubectl describe ns <Filename. Yaml>----------------inspect
of resources
·
Kubectl get ns <Filename. Yaml>-----------------------To
see in Yaml format
1. What is resource quota?
2. What it the difference b/w kubectl create & apply?
Class 004

Comments
Post a Comment