-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s-debug-app
89 lines (65 loc) · 2.76 KB
/
k8s-debug-app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#DEBUG APPs deployment, pod, services, endpoints
kubectl get all
kubectl get deployment,svc,pods,pvc -n <namespace>
#CHECK EVENTS AND REASON BY POD
pod=$(kubectl get pods --selector="name=bad-frontend" --output=jsonpath={.items..metadata.name})
kubectl describe pod $pod
#describe the events for a pod
kubectl describe pod my-nginx | grep -A 3 Events
#debug pods
kubectl describe pods ${POD_NAME}
kubectl describe rc ${CONTROLLER_NAME} # for the replication controllers
#debug logs
kubectl logs ${POD_NAME} ${CONTAINER_NAME}
#debug previous crashes
kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}
#debug endpoints
kubectl get endpoints ${SERVICE_NAME}
#run commands to check
kubectl exec ${POD_NAME} -c ${CONTAINER_NAME} -- ${CMD} ${ARG1} ${ARG2} ... ${ARGN}
kubectl exec cassandra -- cat /var/log/cassandra/system.log
OR
kubectl exec -it container-name -- /bin/bash
OR if multiple containers in the same pod
kubectl exec -it my-pod --container main-app -- /bin/bash
#validate pods yaml files
kubectl create --validate -f mypod.yaml
kubectl delete pod,service baz foo
#get pod yaml on apiserver and compare with your pod spec
kubectl get pods/mypod -o yaml > mypod-on-apiserver.yaml
diff mypod-on-apiserver.yaml newpod.yaml
#get pods by selector and check if the list match with the expected pods to provide your service
kubectl get pods --selector=name=nginx,type=frontend
#verify the pod’s containerPort matches up with the Service’s containerPort
kubectl describe svc my-nginx
#verify the service
kubectl get svc my-nginx
kubectl exec my-nginx-3800858182-e9ihh -- printenv | grep SERVICE
#create
kubectl create -f ./nginx.yaml
#check
kubectl get pods -l run=my-nginx -o wide
#check IP
kubectl get pods -l run=my-nginx -o yaml | grep podIP
#expose a Service, create a service. But better to use a yaml file to create the service kubectl create -f ./nginx-svc.yaml
kubectl expose deployment/my-nginx
#verify your service
kubectl get svc my-nginx
kubectl describe svc my-nginx
#verify your endpoints ep
kubectl get ep my-nginx
#descale and scale, this will kill and recreate them
kubectl scale deployment my-nginx --replicas=0; kubectl scale deployment my-nginx --replicas=2;
#check if skydns kube dns is running
kubectl get services kube-dns --namespace=kube-system
#check nslookup
kubectl run curl --image=radial/busyboxplus:curl -i --tty
nslookup my-nginx
#generate self-signed certificates, generating key pair private and public key
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /tmp/nginx.key -out /tmp/nginx.crt -subj "/CN=my-nginx/O=my-nginx"
#convert to base64
cat /tmp/nginx.crt | base64
cat /tmp/nginx.key | base64
#edit and fill a new nginx-secrets.yaml with the key pair secrets from above step
#and run create the secrets objects
kubectl create -f nginx-secrets.yaml