Kubernetes

1. Basic commands:

kubectl run nginx --image=nginx 

- gets the nginx image from the docker repository and launches apod with name nginx in cluster.

kubectl get nodes
- to get list of nodes

kubectl describe pod nginx

- gets all the properties of pod with nane nginx,like container id,ip address of pod and ip address of node etc

kubectl delete pods <pod name> - To delete pods
kubectl delete replicasets <replicaset name> - To delete replica sets
kubectl delete deployments <deployment name> - To delete deployments

-------------------------------
 kubectl delete --all svc --namespace=default - To delete all services in a namespace at once,similary pods,replicasets and deployments replace svc with pods,rc and deploy respectively 

2. Pods:

Every thing about pods like creating pods using kubectl,using yaml file and remove those etc,nice blog here

3.Replica set:

blog: here
video: here

we can edit replaceset yaml definition file using and use kubectl replace or we can use kubectl edit, so after saving the file automatically changes are trigerred i.e application is scaled up or down

4.Deployment:

updates(recreate and rolling) -> blog
Rollbacks -> blog

Updates and rollbacks,udemy video

Note:Use --record option in kubectl create, you will see change cause in kubectl rollout history 
  1. kubectl rollout undo deployment/nginx-deployment --to-revision=1
  2. to roolback to particular revision

5.Services:

Three types of services:
1.NodePort(click here)

  • A NodePort service exposes the service on the IP of each node at a static port. A ClusterIP service is created automatically to route the traffic to the NordPort service. Users can communicate with the service from the outside by requesting <NodeIP>:<NodePort>
  • Since the pods ips are changed when we restart the pod,to access pods we bind the pods to a service and we access it
  • Consider a sample example of cretaing single or 3 replicas of nginx in cluster, they are not eccessible by the out side cluster,so we use nodeport service to expose seervice running on pods, in production we don't use for testing purposes we can use this
  • Another user case was ingress service,if we generally use ingress controller and ingress service through which outer world access our application in cluster, if k8 cluster was in public or private cloud then we use their load balancer or else if it is installed on premises on a bare metal,then we will use nodeport as load balancer  


2.ClusterIP(Click here)
  • This is the default type that exposes the service on an internal IP of the cluster. These services are only accessible within the cluster. So, users need to implement port forwarding or a proxy to expose a ClusterIP to a wider ingress of traffic.
  • If we don't specify any service type, then by default culsterip service weas created
  • It is used internally within cluster, let say we have a group of pods for frontend and group of pods for backend, then obviously frontend pods needs to communicate with backend pods, so we create cluster ip for frontend and backend pods, this cluster ip service automatically acts as load balancer and reaches in any one of the pods under repsective group 
3.LoadBalancer(Click here)
  • This is the preferred solution to expose the cluster to the wider internet. The LoadBalancer type of service will create a load balancer (load balancer type depends on the cloud provider) and expose the service externally.
  • It will also automatically create ClusterIP and NodePort services and route traffic accordingly.
  • If we have our cluster in cloud,then we specify service type as Loadbalancer then respective cloud providers load balancer is used
  • For testing purpose if we want to use in our local machine,then we use Nodeport
  • If we use in onpremises in production,then proxies are used,instead of load balancers

Example voting app github : https://github.com/dockersamples/example-voting-app

Kubernetes Administrator Notes: here
Slack channel: here


Ingress Networking: Best Video

Comments

Popular posts from this blog

Docker Imp points

Docker volumes backup and restore & Docker networks