Working with kubectl (Kubernetes command line tool) over Linux (Ubuntu) on Windows - yoss123/test-automation-repo GitHub Wiki

Great Kubernetes tutorial: https://www.youtube.com/watch?v=s_o8dwzRlu4

Kubernetes documentation: https://kubernetes.io/docs/home/

---------------------- Course commands -----------------

brew install kubectl
pip3 install aws
pip3 install awscli
aws eks update-kubeconfig --name k8s-training --region us-east-1
kubectl cluster-info

kubectl get pod
kubectl apply -f my_first_kube_pod.yaml
kubectl delete -f my_first_kube_pod.yaml
kubectl logs nginx-yossi

kubectl get deployment
kubectl apply -f my_first_kube_deployment.yaml
kubectl apply -f my_first_kube_deployment.yaml --force #override the exist one
kubectl get deployment nginx-yossi -o yaml
kubectl describe deployment {deployment_name}
kubectl set image deployments nginx-yossi nginx=nginx:latest

kubectl get rs #rs=replica set

working with namespaces
kubectl create ns yossi #define a namespace named yossi
kubectl config set-context --current --namespace=yossi #define a namespace and then I'll see only my resources
kubectl get deployment -n default #shows all the deployments without taking into account my namespace
kubectl get svc -n default #shows all the services without taking into account my namespace

kubectl exec -it <pod_name> # get into the pod

---------------------- End of course commands -----------------

Before installing kubectl you need to install Linux on your machine.<br< https://github.com/yoss123/test-automation-repo/wiki/How-to-install-Ubuntu-on-Windows

Install kubectl (Kubernetes command-line tool) from the next link:
https://kubernetes.io/docs/tasks/tools/#kubectl
In order for kubectl to find and access a Kubernetes cluster, it needs a kubeconfig file. Open ticket to DevOps team to send you this file to install it on your machine (kubecfg.yaml).

Some commands to work with Kubernetes pods:
To get the list of pods (in our application, pod contains a micro-service):
kubectl get pods -n pcn-qa

To view the logs of a pod (there's a log rotation so you'll see the logs starting about 10 or 20 minutes ago or whatever defined by the admin):
kubectl logs -f [pod_name] -n [namespace]
For example:
kubectl logs -f manager-api-799cfc5c57-66r7d -n pcn-qa
To quite showing the log tail press on CTRL+C

To print the logs into a windows file:
kubectl logs -f [pod_name] -n [namespace] > /mnt/[path to file]
For example:
kubectl logs -f manager-api-int-864f764f67-slsnx -n pcn-qa > /mnt/c/AnyClip/temp/logOfPublisher.txt

To view the logs filtered by specific text: (the filter command is a Linux command and not kubectl command)
kubectl logs -f [pod_name] -n [namespace] | grep "[text_to_filter]"
For example:
kubectl logs -f manager-api-799cfc5c57-66r7d -n pcn-qa | grep "GET /version"

Some useful Linux commands
PWD - current working directory (folder) you’re in
CD - To navigate through the Linux files and directories
CD /mnt/[windows_path] - moving from Linux home directory to Windows directory which the Linux is installed on. For example, CD /mnt/c/AnyClip - moving to c/AnyClip directory in Windows
ls - used to view the contents of a directory.
ls -al - will list the files and directories with detailed information like the permissions, size, owner, etc.
For more useful Linus commands click here

---------------------- Working with OpenLens - most popular Kubernetes IDE -----------------

Note that there is another K8s tool that can be used via terminal named K9s.

Download and install OpenLens + add extension
Go to OpenLens (Free edition of the app) and make sure to follow the steps as detailed there. In case brew installation fails, follow the download binary installation (make sure to download the correct dmg file, depends if you’re using intel or arm mac processor.
After installing OpenLens, open it and go to extension tab in the menu. In the extension url input paste @alebcay/openlens-node-pod-menu and click the Install button. App might berserk after you install, so it’s recommend to restart it.
Now you should have all action items for the pod

⚠️ **GitHub.com Fallback** ⚠️