7/22/2016

Kubernetes frequently used commands

Kubernetes:
===========
# Start cluster
# install virtualbox. Enable VT-x and disable secure boot from BIOS if applicable. Then install minikube and kubectl
minikube start
minikube dashboard # To access the dashboard
# Check namespace
minikube get namespace
# Delete a terminating namespace
NS=`kubectl get ns |grep Terminating | awk 'NR==1 {print $1}'` && kubectl get namespace "$NS" -o json   | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/"   | kubectl replace --raw /api/v1/namespaces/$NS/finalize -f -
# Get logs
minikube logs --file=logs.txt

Failed? BE CAREFUL, ALL SERVICES WILL BE GONE. Try:
$minikube stop
$minikube delete && rm -rf ~/.minikube && rm -rf ~/.kube

k cluster-info
kubectl create ns minio-dev # create namespace
k describe pod [pod name]
k get nodes --show-labels
kubectl cordon [node-name]  # Prevent a node from scheduling jobs
kubectl uncordon [node-name] # Resume scheduling jobs on node
k get pod [pod name] -o go-template={{.status.podIP}}
k get pods
k get pods -n [minio-dev]  # -n means namespace
k delete pod [pod name]
k delete pod [pod_name] -n [namespace]
k delete -n default pod [your-pod-name]
k run hello-node --image=hello:v2 --port=8088
k expose pod [pod name] --port 8088
k scale deployment hello-node --replicas=4
k edit deployment hello-node
k apply -f [?]/a.yaml
k get deployment my-nginx -o yaml
k logs [pod id]
k get nodes --show-labels
k port-forward pod/minio 9000 9090 -n minio-dev # Forward port
k port-forward svc/minio -n minio-dev 9090  # Forward port
k rollout restart deployment [deployment_name] -n [namespace]
# Get bash access
kubectl exec -it [pod name, e.g. minio-766dbb8d6d-b6fcq] -n minio-dev  -- /bin/bash

#Careful, service will be down
kubectl replace -f docs/user-guide/nginx/nginx-deployment.yaml --force

http://kubernetes.io/docs/user-guide/docker-cli-to-kubectl/

Kubernetes cluster is running.  The master is running at:

  https://52.34.246.212


The user name and password to use is located in /home/liangzou/.kube/config

No comments: