Kubectl

Linux

https://kubernetes.io/docs/tasks/tools/

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

sudo mv kubectl /usr/local/bin/kubectl

https://www.youtube.com/watch?v=5vW6NOUOd1M

https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/

curl.exe -LO "https://dl.k8s.io/release/v1.32.0/bin/windows/amd64/kubectl.exe"

https://dl.k8s.io/release/stable.txt.



search or path - environment variables user or system wide - Path add C:\tools\

Get-PSDrive /n Get-ChildItem -Path Env: /n dir Env: /n (Get-ChildItem -Path Env:Path).Value (Get-ChildItem -Path Env:Path).Value -split ";" $env:Path -split ';' [System.Environment]::GetEnvironmentVariables() https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariables [System.Environment]::GetEnvironmentVariable('Path') -split ";" [System.Environment]::GetEnvironmentVariable('PATH','User') -split ";" [System.Environment]::GetEnvironmentVariable('PATH','Machine') -split ";" System Variables: HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment PowerShell command to get the value of the Path environment variables in the user scope: (Get-ItemProperty HKCU:Environment).Path -split ";" PowerShell command to get the value of the Path environment variables in the system scope. In the below command gp is the alias of the Get-ItemProperty cmdlet in PowerShell. (gp "HKLM:SYSTEMCurrentControlSetControlSession ManagerEnvironment").Path -split ";" href="https://medium.com/@bonguides25/how-to-get-the-path-environment-variables-using-powershell-4660c8f8c32c#:~:text=To%20retrieve%20all%20the%20environment%20variables%20stored%20in,listed%20first%2C%20and%20then%20the%20value%3A%20Path%20C%3AWindowssystem32%3BC%3AWindows%3BC%3AWindowsSystem32Wbem%3BC%3AWindowsSystem32WindowsPo">Source

Kube config file c:\users\i9\.kube\config

kubectl config view

Linux ls ~/.kube/

linux@DESKTOP-DF4MKR8:/mnt/c/users/i9$ kubectl config view apiVersion: v1 clusters: - cluster: certificate-authority-data: DATA+OMITTED server: https://127.0.0.1:38889 name: kind-test contexts: - context: cluster: kind-test user: kind-test name: kind-test current-context: kind-test kind: Config preferences: {} users: - name: kind-test user: client-certificate-data: DATA+OMITTED client-key-data: DATA+OMITTED linux@DESKTOP-DF4MKR8:/mnt/c/users/i9$

kubectl config current-context

kubectl config use-context kind-test

export KUBECONFIG=~/kubedevonfig

kubectl get nodes

kubectl config view

export KUBECONFIG=~/.kube/config kubectl config view kubectl get nodes --- Kubectl Basics: kubectl basics ## Configs ``` kubectl config #${HOME}/.kube/config #kubectl config --kubeconfig="C:\someotherfolder\config" #$KUBECONFIG ``` ### contexts ``` #get the current context kubectl config current-context #get and set contexts kubectl config get-contexts kubectl config use-context ``` ## GET commands ``` kubectl get #examples kubectl get pods kubectl get deployments kubectl get services kubectl get configmaps kubectl get secrets kubectl get ingress ``` ## Namespaces ``` kubectl get namespaces kubectl create namespace test kubectl get pods -n test ``` ## Describe command Used to troubleshoot states and statuses of objects ``` kubectl describe ``` ## Version ``` kubectl version ```

kubectl create ns example-apps

kubectl -n example-apps create deployment webserver --image=nginx --port=80

kubectl -n example-apps get deploy

kubectl -n example-apps get pods

kubectl -n example-apps get pods -o wide

kubectl -n example-apps create service clusterip webserver --tcp 80:80

kubectl -n example-apps get service

kubectl -n example-apps port-forward svc/webserver 80

kubectl -n example-apps port-forward svc/webserver 8000:80

---

kubectl -n example-apps get deploy webserver -o yaml

Can pass file or folder

kubectl create ns wordpress-site

kubectl -n wordpress-site apply -f ./kubernetes/tutorials/basics/yaml