Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
56 views20 pages

Kubernetes Commands - Sandy

There are two modes of application deployment in Kubernetes: command mode and file mode. Key things needed for authentication are the IP address, port number, and token. The kubeadm token create command is used to generate tokens for joining nodes to the cluster. Networking in Kubernetes is implemented using Calico, which uses the BGP protocol to connect nodes and provides IP addresses to pods.

Uploaded by

sandeep singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views20 pages

Kubernetes Commands - Sandy

There are two modes of application deployment in Kubernetes: command mode and file mode. Key things needed for authentication are the IP address, port number, and token. The kubeadm token create command is used to generate tokens for joining nodes to the cluster. Networking in Kubernetes is implemented using Calico, which uses the BGP protocol to connect nodes and provides IP addresses to pods.

Uploaded by

sandeep singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

1.

There are two modes in Kubernetes in application deployment- Command and File
Mode
2. Commands
3. systemctl is-active kubectl
4. kubectl get componentstatus
netstat -tnlp |grep api
13 netstat -tnlp |grep control
15 netstat -tnlp |grep schedu
16 ls -i /etc/kubernetes/admin.conf----------------- path of Kubernetes config file
17 grep -i server /etc/kubernetes/admin.conf==========to find server port
18 ifconfig eth0========== to find IP
19 netstat -tnlp | grep -w 6443-----------======== TO GREP PORT
20 kubectl get nodes -n kube-system============== -n is name space
21 systemctl is-active docker==============to check serves like kubelet
22 kubectl get pod -n kube-system -o wide=== to check which pod is working for which
node or check ip
23 kubectl get componentstatus =========to check services are working healthy or not
24. vi /etc/host ============TO change host ip to host name
25 to install worker node same repo need to run

26 yum install docker-ce -y


27 systemctl start docker and then enable
Three things we need for authentication
28 this file also need to set

29. We need to raise tokens for security


Kubeadm token list
30 kubeadm token create =========same delete
31 kubeadm token create --ttl-duration 2324===========provide to token
To achieve above three things
32 ifconfig eth0 ====1st check IP add by using command and for token
33 netstat -tnlp | grep -w 6443 === 2nd port no
34 Kubeadm token list ========= 3rd token
35 ls -I /etc/Kubernetes/pki/ca.crt ========4th get certificates
36 Run this command on master node to communicate with cluster node(in this single
command will get all above 4 things at a time)--- to join the cluster
Kubeadm token create --print-join-command

37 kubectl get nodes ==== then check how many nodes are avail in that cluster.

Section 2 – doubt 2
1. Kubectl get events========to GET API major events
2. Kubectl get events -n kube-system === to check in name space
3. To check on pod and other services logs

4 kubectl create ns test =========== to create namespace to separate the team /project

5 kubectl get pod -n test ======to check test namespace pods only
6. to deploy some pods
7 kubectl delete ns webprod ======= to delete
8. kubectl certs check-expiration ==========to check expiration

CALICO NETWORK CREATION


1. Install calico network ==== use below
2.

3. Fire ls command to check yaml file.


4. Kubectl create -f calico.yaml ======= to create yaml file here -f is file.
5. Kubectl get pod -o wide -n kube-system======= to check pod is assigned on which
worker node. Calico switch will give ip.
6. After that node will come in ready state.
7. Kubectl get pod ========= to check number of Pods
8. Kubectl run test --image=docker.io/nginx ===to create pod (test is pod name)
9. . Kubectl get pod -o wide

10. Kubectl scale --replicas=3 rc krcloud=====================to increase replica


containers(krcloud is controller name)
11. Kubectl apply -f rc.yml =========to apply in yaml if we want to update etcd so that
we can see that changes.
12. Kubectl edit rc krcloud============directly we can chage in etcd without yaml file
13. Kubectl get rc krcloud -o yaml > rc.yml============to save file from etcd to yaml
file
Application deployment In Kubernetes Unit 2

1. Kubectl get ns ==========to check name space


2. Kubectl run test --image=docker.io/nginx ========== same as docker run
command (run from docker io hub )
3. Kubectl get pod -o wide ======= to check pod is assigned on which worker node.
Calico switch will give ip.
4. Kubectl logs test ============== to check logs
5. Kubectl exce -it test /bin/bash============ to go inside the pod
6.

7. Above command to change inside the container.


8. Kubectl describe pod test ===== to get more details about that particular pod.
9. Kubectl delete pod test ==================== to delete the pod.
10. Kubectl run test –image=nginx --dry-run -o yaml=======Due to dry run command
we can Just check in File mode in yaml format not execute it.
11. Cat > pod.yaml==============to create pod yaml
CAT – CREATE , Concatenate, Copy , Append

12. Kubectl create -f pod.yml============ to create pod by yaml


13. Cat pod.yml ============= to display pod yaml
14. Kubectl delete pod test ======= delete
15. Vi pod.yml ========= Test for names whatever is mentioned in file(check required
parameters)== change sequences and delete and create pod to understand
16. Kubectl api-resources =========== to check api name definitions in system- pod not
po (Its kind parameter in yaml file)
17. Kubectl explain pod ============ CHECK how to write yaml in sequence
18. Kubectl explain pod.metdata =========to check in metadata field which keys we
can use
19. Kubectl explain pod.spec =========to check in metadata field which keys we can
use
20. Kubectl run test –image=nginx --dry-run -o yaml > pod.yml ===to make yaml file
again
21. Kubectl get pod --show-labels == to check levels live green ,blue

Unit 04 Resource and compute quota -----


=======================================================
1.
2. Kubectl describe node “NODE NAME” | grep -iA5 allocated ======to check
utilization of CPU
3. Kubectl get pod app -o wide============= to check which node is defined for that
pod
Namespace quota---
1. Kubectl create ns webprod ========to create namespace named webprod
2. Kubectl create quota xyz - - hard=memory=800Mi ,cpu=400m -n webprod======
to create quota without ymal
3. Kubectl get quota -n webprod ========= to check quota on name space
4. Kubectl describe quota xyz -n webprod ========= to check quota on name space
Limit Range===========
5. Kubectl delete pod --all -n webprod ========== to delete all pods
6. Kubectl delete quota xyz -n webprod ==========to delete quota
7. Kubectl create quota test --hard=pods=10 , services=10 -n webprod
==============to set pod limit in system after 10 we can not make more pods.
8. Kubectl create quota test --hard=pods=10 , services=10 , memory =512Mi ,
cpu=500m -n webprod========= to set both compute and resource quota over
the namespace
Networking
1. Kubectl create deploy test --image=nginx
2. Kubectl scale --replicas=3 deploy test
3. Kubectl get pod -o wide
4.

5. Kubectl get pod -n kube-system =========to check all pods and networks like
calco

6. Kubectl get ds -n kube-system ========== to check in daemon set how many


nodes are available.
7. Install calcoctl command from

8. Ls command to check
9. Mv calicoctl /bin/
10. Chmod u+x /bin/calicoctl ========== give permission to user to execute
11. This command will not until we to define in API
12. Mkdir -p /etc/calico /
13. Vi /etc/calico/calicoctl.cfg ===========in this file we have define the api path
14.

15. Paste this file

16. Calicoctl ipm show ============= to check wheter it is ready or not


17. Calicoctl get ippool ============= to check ip pool
18. Calico ipm show --show-block =============== to check ippool and blocks
created from ippool

19.
20. Due BGP protocol only we are able to connect one node to another.
21. Ip route ========== to check ip routing gateway connectivity
22. How to create New via calico pool
23. Calicoctl get ippool
24. Calicoctl get ippool “POOL NAME” -o yaml > pool.yml
===============================to copy pool on yaml file
25. Vi pool.yaml ==================== to modify pool
26.

27. Calicoctl create -f pool.yaml =============to create pool


28. Remove resource version and uid in ymal.
29. Calicoctl get ippool
30. Kubectl run test --image=nginx =========Make a pod
31. Kubectl get po test -o wide ============== to check ip address
32. It will show old ip address we need to activte new pool
33. Calicoctl get ippool “POOL NAME” -o yaml > pool.yml
===============================to copy pool on yaml file to disable old pool
34. Vi pool.yaml ============= to disabled
35. Calicoctl apply -f pool.yaml ================ to apply
36. Now create new pod and check ip address
37. Kubectl run test --image=nginx =========Make a pod
38. Kubectl get po test -o wide ============== to check ip address
39. Calicoctl ipam show ========= to check all pools
40. Delete new pool and again assign old pool
Service IP allocation (kube
proxy)=====================================================================
1. Two tier integration
2. Kubectl expose deploy db - - port=80========== to create/get service ip
3. Kubectl get service db
4. Kubeadm init - - help
5. Kubectl describe service db============= to check end points
6. Kbectl get pod -o wide ==========
7. Need to check video
8. Service IP by yaml
9.

cat

10. Cat > service.yml

11. Kubectl create -f service.yml


12. Kubectl get service
13. Curl “webserver ip:port”
14.

15. If we are creating through command line (expose command) noo need to provide
target port
CORE DNS===================
90. kubectl create deploy test --image=nginx
91 kubectl get po
92 kubectl delete test-844b65666c-lxnhb
95 kubectl exce -it test-844b65666c-lxnhb /bin/bash
96 kubectl exec -it test-844b65666c-lxnhb /bin/bash
97 kubectl expose deploy test --port=80 --target-port=80 --name=frentend
98 kubectl get service frentend
99 kubectl run client --image=nginx =================== WE CAN CURL THIS CILENT
BY NAME AND IP
100 kubectl exec -it client /bin/bash
11. kubectl get po -n kube-system =========== to check which services are running
How to connect with ext
Ips=========================================================================
===============================
1.kubectl expose deploy test - -port=80 - -name=frontend - -type=NodePort
==============node port is being used for port forwarding for ext network
2. kubectl get service frontend

Network proxy====================================
1. Copy network policies from Kubernetes.io
2.
3. This is for ingress policy, in this we db node can connect with app node only
4.
5. Go inside the wed pod and check ping
6.

7. Make new pod with new namespace and labels would be same app=app but we
cannot ping with db because all criteria is not matching- in old we didn’t mention
namespace.
8. Rule 2 means jo b project example mein will come that will allowed
9.

10. But Here we have to edit name because Kubernetes only knows labels
11. Kubectl edit ns example
12.
13. Now we reach the db pod because criteria mein we can change label and
namespace changed
14. Kubectl create -f netpol.yml ============== to make policy
15. Two rule mentioned above 1. Ping db to app within same namespace 2 Ping db to
app in diff namespace
16. Kubectl describe -f netpol.yml

17.
18. Example of AND rule -If we are not mentioning (-) in front of namespaceselector

19.
20. Example of OR rule -If we are mentioning (-) in front of namespaceselector
21. Kubectl apply -f net.yml ============== to reapply the policy
22.

23. Now showing two from in OR rule


Policy session -3

24.
25. This {} means we are allowing to all pod which are part of example name space and
containing 80 port

Volumes
lab========================================================================
=======================================================================
First we have to install NFS server
Yum install nfs-utils -y ============= to share storage over network for multiple server

1. mkdir -p /opt/nfs
2. vi /etc/export

You might also like