-
Notifications
You must be signed in to change notification settings - Fork 4
Commands
kubectl get all
kubectl get all -o wide
kubectl get all --all-namespaces -o wide # --al-namespaces -> -A
kubectl get nodes
kubectl get pods
kubectl cluster-info
kubectl get events
kubectl get services
kubectl create -f input.yaml
kubectl delete pod $POD_NAME
kubectl exec -it busybox /bin/sh
kubectl exec busybox nslookup kubernetes.default
kubectl describe nodes
kubeadm reset # Reverts any changes made by kubeadm init or kubeadm join
kubeadm token list # Run this on master node to get token
kubeadm join --token $token $master_node_ip:6443 --discovery-token-unsafe-skip-ca-verification # Don't skip verf, its just for local
kubectl get netpol -n $NAMESPACE # List network polices. (netpol or networkpolicy)
kubectl describe netpol $NET_POLICY_NAME -n $NAMESPACE
kubectl delete netpol $NET_POLICY_NAME -n $NAMESPACE
kubectl delete -f $NET_POLICY_RESOURCE.yaml -n $NAMESPACE
kubectl edit netpol $NET_POLICY_NAME
kubectl edit netpol $NET_POLICY_NAME -n default -o json
kubectl edit -f $NET_POLICY_RESOURCE.yaml
KUBE_EDITOR='nano' kubectl edit netpol access-nginx -n default # nano or vim etc
kubectl config set-context --current --namespace=$NAMESPACE # set default NAMESPACE
kubectl get netpol $NET_POLICY_NAME -n $NAMESPACE -o json
kubectl config view --minify --output 'jsonpath={..namespace}' # get current namespace
kubectl get pods -n $NAMESPACE -w # -w is watch
kubectl get serviceaccounts -A -o yaml # list all service accounts
kubectl delete pod <pod_name> --grace-period=0 --force -n # force delete pod
--dry-run
It just displays the yaml of the manifest but doesn't creates the object.
$ kubectl create namespace ttt -o yaml --dry-run
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: ttt
spec: {}
status: {}
Kind of MAN page of the object `explain
$ kubectl | grep explain
explain Documentation of resources
$ kubectl explain pod
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
kind <string>
...
$ kubectl explain pod.apiVersion
$ kubectl explain pod.spec
Show complete schema of the object
$ kubectl explain pod --recursive
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
kind <string>
metadata <Object>
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
initializers <Object>
pending <[]Object>
name <string>
result <Object>
apiVersion <string>
code <integer>
details <Object>
causes <[]Object>
field <string>
message <string>
reason <string>
...
$ kubectl explain pod.metadata --recursive
KIND: Pod
VERSION: v1
RESOURCE: metadata <Object>
DESCRIPTION:
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
ObjectMeta is metadata that all persisted resources must have, which
includes all objects users must create.
FIELDS:
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
Supported API resources on the server
$ kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
...
Supported API versions on the server, in the form of "group/version"
$ kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
...
v1