Kubernetes useful commands

!!This is a draft document!!

Minikube Setup Commands

Linux: curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version
Linux: curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.23.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
minikube start
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
kubectl expose deployment hello-minikube  --type=NodePort
kubectl get pod
curl $(minikube service hello-minikube --url)
kubectl delete deployment hello-minikube
minikube stop

Basic Kubectl Commands

kubectl get pods
kubectl get pods [pod name]
kubectl expose  <identifier/name> [—port=external port] [—target-port=container-port [—type=service-type]
kubectl port-forward  [LOCAL_PORT:]REMOTE_PORT]
kubectl attach  -c 
kubectl exec  [-it]  [-c CONTAINER] — COMMAND [args…]
kubectl label [—overwrite]  KEY_1=VAL_1 ….
kubectl run  —image=image

Scaling Commands

kubectl scale —replicas=4 deployment/tomcat-deployment
kubectl expose deployment tomcat-deployment --type=NodePort
kubectl expose deployment tomcat-deployment —type=LoadBalancer —port=8080 —target-port=8080 —name tomcat-load-balancer
kubectl describe services tomcat-load-balancer
kubectl describe services tomcat-load-balancer

Deployments Commands

kubectl get deployments kubectl rollout status kubectl set image kubectl rollout history

Secret Commands

kubectl create secret generic db-user-pass --from-file=./username.txt --from-file=./password.txt
kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD