To start with anything on command line: To understand the meaning of yaml files use
Kubectl explain <objecttype>
Kubectl explain pods
Kubectl explain pods.spec
To see the logs of a container
docker logs <container id>
kubectl logs <podname>
kubectl logs <podname> -c <containername>
Container logs are automatically rotated daily and every time the log file reaches 10MB in size. The kubectl logs command only shows the log entries from the last rotation.
kubectl version
kubectl cluster-info
kubectl config current-context
kubectl get componentstatus
kubectl describe <objecttype> <objectname>
kubectl edit <objecttype> <objectname>
kubectl delete <objecttype> <objectname>
kubectl create -f <object.yaml>
kubectl apply -f <object.yaml>
kubectl get serviceaccounts
kubectl get pod/kube-apiserver-kubemaster-01 -n kube-system -o json
kubectl get deploy/<deplyment-name> -o json
kubectl rollback history deploy/<deployment-name>
kubectl rollback
kubectl get secrets
kubectl describe secret/default-token-3dj6w
kubectl get secret/default-token-3dj6w -o json
kubectl get role/<role-name> -o json
kubectl get rolebinding/<rolebinding-name> -o json
kubectl get pods --all-namespaces
kubectl get pods
kubectl describe pod/<podname>
kubectl describe pod/<podname> -o json|wide
kubectl exec <podname> -c <containername> -i -t -- bash
kubectl exec -it <containername> -- /bin/bash
kubectl get pods --show--labels
kubectl get pods --selector <key-label>=<value-label>
kubectl get pods -l <key-label>=<value-label>
kubectl get pods -l '<label-name> in (label-value1, label-value2)'
e.g. : kubectl get pods -l 'env in (dev, prod)'
Controller Deployment logs kubectl get deploy/ -o json
pod logs kubectl logs pod/
To get more columns in the result use -L
kubectl get po -L creation_method,env
NAME READY STATUS RESTARTS AGE CREATION_METHOD ENV
kubia-manual 1/1 Running 0 16m <none> <none>
kubia-manual-v2 1/1 Running 0 2m manual prod
kubia-zxzij 1/1 Running 0 1d <none> <none>
To get more all the pods that have label creation_method:manual
kubectl get po -l creation_method=manual
To list all pods that include the env label, whatever its value is:
kubectl get po -l env
NAME READY STATUS RESTARTS AGE
kubia-manual-v2 1/1 Running 0 37m
namespaces
kubectl config set-context current-context --name-space name-space-name
When you want to figure out why the previous container terminated, you’ll want to see those logs instead of the current container’s logs. This can be done by using the --previous option:
kubectl logs mypod --previous
Instead of using the kubectl scale command, you’re going to scale it in a declarative way by editing the ReplicationController’s definition:
kubectl edit rc kubia
When deploying a pod, you don’t need to constantly poll the list of pods by repeatedly executing kubectl get pods. Instead, you can use the --watch flag and be notified of each creation, modification, or deletion of a pod,
kubectl get pods --watch
Both the Control Plane components and the Kubelet emit events to the API server as they perform these actions. They do this by creating Event resources, which are like any other Kubernetes resource.
kubectl get events --watch
Remove the taints on the master so that you can schedule pods on master as well.
kubectl taint nodes --all node-role.kubernetes.io/master-
Run Kubectl with better logging to see what kubectl is doing.
kubectl get pods -v=8
kubectl delete all --all