12. DOCKER & KUBERNETES : KUBERNETES ARCHITECTURE
https://drive.google.com/file/d/1fd2gYPFaOfKU48u_XB3OMP99yZIkrc2N/view?usp=sharing
#######################################################################
KUBERNATES
#######################################################################
############################Every day activity on Kubernates#####################
//in normal cmd - COMMAND1
----------
C:\Program Files\Kubernetes\Minikube\minikube start
//verify
minikube status
kubectl cluster-info
//you will see : Kubernetes master is running at https://192.168.99.101:8443
//All master service will run even in each Node also
//we see minikube server
//another cmd - COMMAND2
--------
minikube dashboard
//you will see browser opening - http://127.0.0.1:52935/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=default
############################Every day activity on Kubernates#####################
//In 1st Terminal (minicube terminal)
//How many nodes are there
kubectl get nodes
//NAME STATUS ROLES AGE VERSION
//minikube Ready master 169m v1.17.0
//it has master act as dual (both master and node)
kubectl get namespaces
//NAME STATUS AGE
//default Active 171m
//kube-node-lease Active 171m
//kube-public Active 171m
//kube-system Active 171m
//kubernetes-dashboard Active 170m
kubectl describe node minikube
//same as inspect in docker, and inspect can work on any object
//but here we have to mention which object (eg: node)
//tells how many CPU's : 2
//momory ~2GB
//pods 110 //this is quota
//OS Image : Buildroot 2019.02.7
//OS : Linux
//Container Runtime : docker://19.3.5
kubectl describe namespaces kube-system
//No resource quota
//No LimitRange resources
//to check all the objects available
//In GIT bash terminal
kubectl api-resources
//nodes no
//namespaces ns
//pods po
//bindings
//services svc
//deployments ds
kubectl api-resources | grep pod //will not work
//normal terminal
//what are all pods in kube-system
//here we can see all pods(services) available for kube-system, which mentioned in image Master
kubectl get po -n kube-system //kube-sysem : its namespace
//kubectl get po - No resources found in default namespace so we have to give name space as above
//NAME READY STATUS RESTARTS AGE
//coredns-6955765f44-4tnjq 1/1 Running 0 3h8m
//coredns-6955765f44-jbnn8 1/1 Running 0 3h8m
//etcd-minikube 1/1 Running 0 3h8m
//kube-addon-manager-minikube 1/1 Running 0 3h8m
//kube-apiserver-minikube 1/1 Running 0 3h8m
//kube-controller-manager-minikube 1/1 Running 0 3h8m
//kube-proxy-pthhz 1/1 Running 0 3h8m
//kube-scheduler-minikube 1/1 Running 0 3h8m
//storage-provisioner 1/1 Running 0 3h8m
kubectl get deployment -n kube-system
//NAME READY UP-TO-DATE AVAILABLE AGE
//coredns 2/2 2 2 3h10m
kubectl get po -n kube-system -o wide
kubectl describe pod etcd-minikube
//normal termial
minikube ssh
sudo -i
ls /var
ls /var/lib
ls /var/lib/minikube
ls /var/lib/minikube/etcd
ls -a /var/lib/minikube/etcd/member
//where is docker running
ps ax | grep dockerd
//2545 ? Ssl 5:48 /usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --default-ulimit=nofile=1048576:1048576 --tlsverify --tlscacert /etc/docker/ca.pem
//all docker command will work here
//kubectl will not work here
//in kubectl terminal
kubectl get deploy -n kube-system
//---------list pods belonging to particular deployment---------------------
//kubectl get po -n kube-system will list down all the pods but we have to filter
//1st get the selector:filter
kubectl get deployments -n kube-system -o wide
//we will get : selector as "k8s-app=kube-dns"
//2nd give selector
kubectl get po -n kube-system -l k8s-app=kube-dns //give above selector - k8s-app=kube-dns
---------------------------------------------------------------
//create namespace
kubectl create ns demo
//namespace/demo created
kubectl describe ns demo
//No resource quota
//No LimitRange resource
//going to deploy in to namespace
//1st create deployment
//creating deployment "nginx-deployment" in namespace = "demo" with pod contains continers of "nginx" with replicaiton of 2
//it will create 2 POD as replica is 2
//pod contains container of "nginx"
kubectl run nginx-deployment --image=nginx --port=80 --replicas=2 -n demo
kubectl get pods -n demo
//we see 2 pods
//go inside the pod
kubectl exec -i -t nginx-deployment-5567b746cd-dt28v bash -n demo
exit
//verify pods are running or not
kubectl get pods -n demo
//increase the replica from 2 to 4 ----------------------
//1st check how many replica we have
kubectl get deployments -n demo
//2/2
//we use edit
kubectl edit deployment nginx-deployment -n demo
//opens a YAML file
//under spec: replicas:2 //modify from 2 to 4
kubectl get deployments -n demo
//now we see 4/4
//nginx-deployment 4/4 4 4 11m
kubectl get pods -n demo
//we will see 4 Pods bez replica is 4
//decrease the replica to 2
//instead of edit, use scale : another way to change replica
kubectl scale deployment nginx-deployment --replicas=2 -n demo
kubectl get pods -n demo
////we will see 2 pods again
kubectl delete pod nginx-deployment-5567b746cd-8bnmx -n demo
//deleted
kubectl get pods -n demo
////we will see 2 pods again bez deployment maintains replica 2 always
//to check what events done on this namespace
kubectl get events -n demo
//88s Normal Pulling pod/nginx-deployment-5567b746cd-79cbc Pulling image "nginx"
//83s Normal Pulled pod/nginx-deployment-5567b746cd-79cbc Successfully pulled image "nginx"
//83s Normal Created pod/nginx-deployment-5567b746cd-79cbc Created container nginx-deployment
LOGS#########################
1. Service logs
2. POD logs
3. Namespace logs
kubectl get pods -n demo
kubectl describe pod nginx-deployment-5567b746cd-79cbc -n demo
//how to check whether service running in pod or not
//we have 2 pods
kubectl describe pod nginx-deployment-5567b746cd-79cbc -n demo
//Port: 80/TCP
//Host Port: 0/TCP
//means service is not running
//Create Extenrnal service-###############################################
//Expose the deployment outside the cluster (means : public servvice)
//going to expose all deployments
kubectl get deployments -n demo //check how many deployments we have
//expose
kubectl expose deployment nginx-deployment --type=NodePort -n demo
//service/nginx-deployment exposed
kubectl get services -n demo
//NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
//nginx-deployment NodePort 10.96.149.146 <none> 80:31032/TCP 16s
kubectl describe svc nginx-deployment -n demo
//Endpoints: 172.17.0.10:80,172.17.0.6:80
//bez we have 2 pods we get 2 ips
minikube ip
//192.168.99.101
minikube service nginx-deployment -n demo
//it will open the browser with ip and port
//192.168.99.101
//Create Internal service-###############################################
kubectl run nginx-internal --image=nginx --port=80 -n demo
//deployment.apps/nginx-internal created
kubectl get deployments -n demo
kubectl expose deployment nginx-internal --type=ClusterIP -n demo
kubectl get services -n demo
//nginx-internal ClusterIP 10.96.149.15
minikube service nginx-internal -n demo //since service is exposed as internal
NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|--------------|
| demo | nginx-internal | | No node port
//since service is exposed as internal we cannot open in browser
//another termial ssh machine (minikube ssh)
curl 10.96.149.15:80
//we see index.html
//Expose service as External IP (LoadBalancer) ###############################################
//For this we should have Cloud
//Showing in Google Cloud
kubectl run nginx-external --image=nginx --port=80
kubectl get deployments
kubectl expose deployment nginx-external --type=LoadBalancer
kubectl get services
//wait for service it will show ip
//open browser
http://35.188.191.136/
-----------------------------------------------------
//all services available
kubectl get services -n kube-system
//TCP -> gateway to POD
//UDP -> POD to POD communication...
minikube addons list
//metrics server
//we will enable metrics server (Monitoring tool)
minikube addons enable metrics-server
// metrics-server was successfully enabled
kubectl get pods -n kube-system
//we see metrics running
//close minikube dashboard browser which was open
//come out from minikube dashboard (Ctrl + C)
//run again
minikube dashboard
//again browser will open with dashboard with graphs
//leftside navigation - Nodes
//click on minikube link below
//filter namespace "demo"
//we see pods , its memory etc...
//How to create a POD with out deployment############################
kubectl run --generator=run-pod/v1 --image=nginx nginx-pod --port=80
//POD is created without deployment, we did not get warning bez we used --generator
//it will create in default namespace
kubectl get pods
//delete pod
kubectl delete pod nginx-pod
//deleted
//to pass env variable in command
//in YAML we hardcoded password in docker file
//but in kubernates we can pass in command
kubectl get secrets
//describe with name given above command
kubectl describe secret default-token-q4ql9
//token: eyJhbGciOiJSUzI1NiIsImtpZCI6Ik1HWGlrdnhUQjNPUC1kMDNJMVpYUEhlQ3BCYVY1ZWMwOTdfUVQ
//ca.crt: 1066 bytes
//namespace: 7 bytes
//we will create similar secret file with username and password
kubectl create secret generic db-pass-values --from-literal=username=root --from-literal=password=admin
//secret/db-pass-values created
kubectl get secrets
//we see new entry which we created - "db-pass-values"
//db-pass-values Opaque 2 42s
//default-token-q4ql9 kubernetes.io/service-account-token 3 6h44m
kubectl describe secret db-pass-values
//Name: db-pass-values
//Namespace: default
//Labels: <none>
//Annotations: <none>
//In real time only we can manage deployment, we cannot create, delete deployments
//get roles
kubectl get clusterroles -n kube-system
//NAME AGE
//admin 6h46m
//cluster-admin
kubectl describe clusterroles admin -n kube-system
No comments:
Post a Comment