~/.kube/config is the local configuration file (contains all the contexts, information about the clusters and user credentials)
# get current contextkubectlconfigcurrent-context# display context configurationkubectlconfigget-contexts# change contextkubectlconfiguse-context<cluster-name>
Cluster information
# display versionkubectlversion# display cluster informationkubectlcluster-info# display cluster configurationkubectlconfigget-clusters# get health information for the control plane components (the scheduler, the controller manager and etcd)kubectlgetcomponentstatuses# list all the nodes in the cluster and report their status and Kubernetes versionkubectlgetnodes# show the CPU and memory capacity of each node, and how much of each is currently in usekubectltoppods# view sereval resources at oncekubectlgetdeploy,rs,po,svc,ep
Management
# create resources from a manifest filekubectlcreate-f<filename># create or update resources from a manifest filekubectlupdate-f<filename># delete resources from a manifest filekubectldelete-f<filename>
Objects
Namespaces (ns)
# list all namespaceskubectlgetnamespaces# create a new namespacekubectlcreatenshello-there
Pods
# list pods of a specific namespacekubectlgetpods--namespacekube-system# list pods of all namespaceskubectlgetpods-A# get more information about a podkubectldescribepod# get log information of a specific podkubectllogs# get pod yaml definitionkubectlgetpod-oyaml# watch podswatchkubectlgetpod--all-namespaces# desribe a podkubectldescribepod<pod-name>--namespace<namespace># get pod logskubectllogs [--tail=20] [--since=1h] <pod-name># display metrics about a pod and its containerskubectltoppod<pod-name>--containers# execute commands inside a pod (for investigation purpose)kubectlexec-it<pod-name>-n<namespace>--/bin/bash# download or upload files from a containerkubectlcpmy-file.txt<namespace>/<pod-name>:my-file.txtkubectlcp<namespace>/<pod-name>:my-file.txtmy-file.txt
ServiceAccounts
# see all service accounts in all namespaceskubectlgetServiceAccount-A
Definitions
CustomResourceDefinition
RBAC
ClusterRole
ClusterRoleBinding
Role
RoleBinding
MutatingWebhookConfiguration
ValidatingWebhookConfiguration
Secrets
# see all secrets in all namespaceskubectlgetsecrets-A
CronJobs (cj)
# create a CronJobkubectlcreatecronjobmy-cron--image=busybox--schedule="*/5 * * * *"--echohello# update a CronJobkubectleditcronjob/my-cron# update a CronJob with a specific IDEKUBE_EDITOR="nano"kubectleditcronjob/my-cron# delete a CronJobkubectldeletecronjobmy-cron
ConfigMap
Deployments
kubectlgetdeployment
Services
# see all services in all namespaceskubectlgetservices-A