Kubectl
Kubectl
is the preferred k8s client used to interact with k8s objects. By default the kubectl client interacts with the cluster kubeconfig specified in the KUBECONFIG
i.e export KUBECONFIG=/PATH/TO/KUBECONFIG.yaml
environment variable file location or explicitly specify kubeconfig using the --kubeconfig <KUBE_CONFIG_FILE_LOCATION>
ℹ️
For easier and faster working with kubectl
, create an alias, so that we don’t have to write the whole thing again
alias k='kubectl' # add to .bashrc or .zshrc
# Usage:
k get pods # instead of `kubectl get pods`
Structure of Command
kubectl [command] [TYPE] [NAME] [flags]
kubectl logs nginx-nxs1a -n test
# Command => create, get, describe, delete, run etc
# Type => configmaps, events, namespaces, nodes etc
# name => name of the k8s resource
# flags => additional flags for the kubectl i.e
Detailed kubectl docs can be found in the link
k8s Object types/resources
available k8s objects/resource can be fetched using the command kubectl api-resources
Most commonly used ones are:
- configmaps / cm
- endpoints / ep
- events / ev
- namespaces / ns
- nodes / no
- persistentvolumeclaims / pvc
- persistentvolumes / pv
- pods / po
- secrets
- serviceaccounts
- service / svc
- customresourcedefinitions / crds
- deployments / deploy
- statefulsets / sts
- horizontalpodautoscalers / hpa
- cronjobs / cj
- jobs
- ingress / ing
- storageclass / sc
kubectl flags
- For exhaustive flags list refer docs
Options | Description |
---|---|
--kubeconfig='<CONFIG_PATH>' | Explicit specify the kubeconfig file otherwise will use the default kubeconfig specified in KUEBCONFIG env variable |
--context='<CONTEXT_NAME>' | specify the context to use |
--cluster='<CLUSTER_NAME>' | specify cluster name |
--insecure-skip-tls-verify=false | If true, the server’s certificate will not be checked for validity. This will make your HTTPS connections insecure |
-v or --v=0 | log level verbose |
-n <NAME_SPACE> | execute the command for the specified NAME_SPACE |