@@ -24,11 +24,15 @@ kubens -
2424```
2525
2626### k9s
27+
2728Kubernetes CLI To Manage Your Clusters In Style!
29+
2830``` shell
2931k9s
3032```
33+
3134### Kubectl commands
35+ >
3236> commonly used Kubectl commands
3337
3438> you can pratice kubectl commands at [ katacoda] ( https://www.katacoda.com/courses/kubernetes/playground ) playground
@@ -62,6 +66,7 @@ kubectl get po --all-namespaces | awk '{if ($4 ~ /Evicted/) system ("kubectl -n
6266### Namespaces and Context
6367
6468> Execute the kubectl Command for Creating Namespaces
69+
6570``` shell
6671# Namespace for Developers
6772kubectl create -f namespace-dev.json
@@ -72,6 +77,7 @@ kubectl create -f namespace-prod.json
7277```
7378
7479> Assign a Context to Each Namespace
80+
7581```
7682# Assign dev context to development namespace
7783kubectl config set-context dev --namespace=dev --cluster=minikube --user=minikube
@@ -82,6 +88,7 @@ kubectl config set-context prod --namespace=prod --cluster=minikube --user=minik
8288```
8389
8490> Switch to the Appropriate Context
91+
8592```
8693# List contexts
8794kubectl config get-contexts
@@ -96,9 +103,11 @@ kubectl config current-context
96103```
97104
98105> see cluster-info
106+
99107``` shell
100108kubectl cluster-info
101109```
110+
102111> nested kubectl commands
103112
104113``` shell
@@ -115,6 +124,7 @@ curl http://localhost:8080/api/v1/namespaces/default/pods
115124```
116125
117126### Accessing logs
127+
118128``` shell
119129# get all the logs for a given pod:
120130kubectl logs my-pod-name
@@ -127,20 +137,25 @@ kubectl alpha diff -f mything.yml
127137```
128138
129139### Execute commands in running Pods
140+
130141``` shell
131142kubectl exec -it my-pod-name -- /bin/sh
132143```
133144
134145### CI/CD
146+ >
135147> Redeploy newly build image to existing k8s deployment
148+
136149```
137150BUILD_NUMBER = 1.5.0-SNAPSHOT // GIT_SHORT_SHA
138151kubectl diff -f sample-app-deployment.yaml
139152kubectl -n=staging set image -f sample-app-deployment.yaml sample-app=xmlking/ngxapp:$BUILD_NUMBER
140153```
141154
142155### Rolling back deployments
156+ >
143157> Once you run ` kubectl apply -f manifest.yml `
158+
144159``` shell
145160# To get all the deploys of a deployment, you can do:
146161kubectl rollout history deployment/DEPLOYMENT-NAME
@@ -151,6 +166,7 @@ kubectl rollout undo deployment/DEPLOYMENT_NAME
151166```
152167
153168### Tips and Tricks
169+
154170``` shell
155171# Show resource utilization per node:
156172kubectl top node
@@ -162,7 +178,8 @@ watch kubectl top node
162178kubectl get po --v=8
163179```
164180
165- #### troubleshoot headless services
181+ #### troubleshoot headless services
182+
166183``` shell
167184k get ep
168185# ssh to one of the container and run dns check:
@@ -190,6 +207,7 @@ bb sh
190207```
191208
192209> after SSH to a container, you can use this command to check connectivity to external host
210+
193211``` shell
194212 # install netcat only if missing
195213apt update && apt -y install netcat
@@ -199,7 +217,9 @@ nc -zv some_egress_hostname 1433
199217```
200218
201219#### Container Security
220+ >
202221> for better security add following securityContext settings to manifest
222+
203223``` yaml
204224securityContext :
205225 # Blocking Root Containers
@@ -214,10 +234,10 @@ securityContext:
214234 add : ["NET_BIND_SERVICE"]
215235` ` `
216236
217-
218237#### Debug k8s
219238
220239For many steps here you will want to see what a ` Pod` running in the k8s cluster sees. The simplest way to do this is to run an interactive busybox `Pod`:
240+
221241` ` ` shell
222242kubectl run -it --rm --restart=Never busybox --image=busybox sh
223243` ` `
@@ -253,20 +273,21 @@ kubectl get secret keycloak-secrets-tls-o jsonpath="{.data.tls.crt}" | base64 --
253273yq '.data."tls.crt"' keycloak-secrets-tls.yml | base64 --decode
254274` ` `
255275
256- # ### iTerm2 tips
257- > in iTerm2
276+ # ### Ghostty tips
277+ >
278+ > in Ghostty
279+
2582801. split screen horizontally
2592812. go to the bottom screen and split it vertically
260282
261283I was using top screen for the work with yaml files and kubectl.
262284
263285Left bottom screen was running :
264286
265- watch kubectl get pods
287+ watch kubectl get pods
266288
267289Right bottom screen was running :
268290
269- watch "kubectl get events --sort-by='{.lastTimestamp}' | tail -6"
291+ watch "kubectl get events --sort-by='{.lastTimestamp}' | tail -6"
270292
271293With such setup it was easy to observe in real time how my pods are being created.
272-
0 commit comments