Getting Started with Kubernetes
# Install KubeCtl
brew install kubectl
# Starting Minikube
minikube start
# Run Hello World
kubectl run hello-world --replicas=2 \
--labels="run=load-balancer-example" \
--image=gcr.io/google-samples/node-hello:1.0 \
--port=8080
# Get Deployments
kubectl get deployments hello-world
# Describe Deployments
kubectl describe deployments hello-world
# Expose Service
kubectl expose deployment hello-world --type=NodePort --name=example-service
# Describe Services
kubectl describe services example-service
kubectl describe svc example-service
# Delete Pods
kubectl delete pods <podname>
# Running Kubernetes Pod
kubectl run <PodName> --image=<image_name> -l app=appName,env=prod,version=1.0 -r 2
# Delete Pod
kubectl delete pod <podName>
# Get Deployment Information
kubectl get deployments
# Applying KubeCtl Applying Resource Configuration
kubectl apply -f <file1> -f <file2>
# Scale Deployments
kubeclt scale deployment guestbook-service --replica=1
# Executing commands on K8 Pods
kubectl exec <podname> -- <command>
# Get a Shell to a Running Container
kubectl exec --stdin --tty <podname> -- /bin/sh
# Kubernetes Configs
# Get Kubernetes Contexts
kubectl config get-contexts
# Display the current Context
kubectl config current-context
# Set the Default Context to <context-name>
kubectl config use-context <context-name>
-----
# Viewing, Finding Resources
$ kubectl get pods
$ kubectl get pods --all-namespaces # List all pods in all namespaces
$ kubectl get deployment my-dep # List a particular deployment
# Describe with Verbose Output
$ kubectl describe pods my-pod
# Interacting with Pods
$ kubectl logs my-pod # dump pod logs (stdout)
$ kubectl logs -f my-pod # stream pod logs (stdout)
$ kubectl attach my-pod -i # Attach to Running Container
$ kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
kubectl logs -f <podname>
kubectl attach redis -i
kubectl port-forward redis-izl09 6379
kubectl exec redis-izl09 -- ls /
kubectl label pods redis-izl09 mylabel=awesome