# get the list of nodes
>kubectlgetnodes
# get details of a selected node
>kubectldescribenode<nodename>
# delete a node
>kubectldeletenode<nodename>
namespace
# get the list of namespaces
>kubectlgetnamespaces
>kubectlgetnamespaces
>kubectlgetns
# create a new namespace# > kubectl create namespace <namespace name>
>kubectlcreatenamespacens1
# delete a namespace# this command will also delete all the objects under the namespace# > kubectl delete namespace <namespace name>
>kubectldeletenamespacens1
pod
# get the list of pods running in default namespace
>kubectlgetpods
# get the list of pods running in requirement namespace
>kubectlgetpods-n<nsname>
# get the list of pods with wide/more options
>kubectlgetpods-n<nsname>-owide
# create a pod using pod1.yaml file
>kubectlcreate-fpod1.yaml
# get the details of selected pod
>kubectldescribepod<podname>
# delete the pod from default namespace
>kubectldeletepod<podname>
# delete the pod from required namespace
>kubectldeletepod<podname>-n<nsname>
# get the logs of a selected pod
>kubectllogs<podname>
# get the logs continuously of a selected pod
>kubectllogs-f<podname>
# execute a command inside a pod
>kubectlexec-it<podname>--<command>
# get the terminal of a selected pod
>kubectlexec-it<podname>--bash
# get the terminal of a selected pod from a selected containers# if -c is not given, the first container will execute the command
>kubectlexec-it<podname>-c<containername>--bash
replica sets
used to create multiple replicas of selected pod
# get list of replica-set
>kubectlgetreplicasets
>kubectlgetreplicaset
>kubectlgetrs
# get details of selected replica-set
>kubectldescribers<rsname>
# to scale out or in, update the replicas in yaml file
>kubectlapply-f<rsyamlfile>
# delete a replica-set
>kubectldeletereplicaset<rsname>
service
used to balance the load amongst multiple pods
these multiple pods can be created using replica-set or deployment
types
ClusterIP
service which will be accessible only within the cluster
service can not be accessed outside the cluster
can be used to access an application inside the cluster by other pods
e.g. frontend pod is accessing backend service which is load balancing the backend pods
ports
port
the internal client will send the request to service on this port
you are free to choose this port as per your requirement
targetPort
service will forward the request to pod(s) on this port
this port number must be same as the port on which the pod is listening on
NodePort
service will make the application accessible outside the cluster
it internally will create a clusterIP service
ports
port
the internal client will send the request to service on this port
you are free to choose this port as per your requirement
targetPort
service will forward the request to pod(s) on this port
this port number must be same as the port on which the pod is listening on
nodePort
the port assigned to the node on which external client will send the request
if needed you can specify the nodePort within the range of 30000-32767
if not specified, the kubernetes will assign a random nodePort to the service
LoadBalancer
used to create a load balancer in cloud (for AWS it will create ALB)
# get the list of services
>kubectlgetservices
# get the service details
>kubectldescribeservice<servicename>
config map
collection of key-value pairs (configuration)
used for storing non-sensitive application configurations
e.g. port number, backend url
all the configurations stored in config map are exposed to the application
via environment variables
all values must be in string format (wrapped in double quotes)
# get the list of config maps
>kubectlgetconfigmap
>kubectlgetcm
# get details of selected config map
>kubectldescribecm<cmname>
# delete selected config map
>kubectldeletecm<cmname>
secrets
collection of key-value pairs (configuration)
used for storing sensitive application configurations
e.g. password, secret, access token
all the configurations stored in secrets are exposed to the application
via environment variables
all values must be in bas64 encoded string format (wrapped in double quotes)
# get the list of secrets
>kubectlgetsecrets
# get details of a selected secret
>kubectldescribesecret<secretname>
# delete selected secret
>kubectldeletesecret<secretname>
deployment
represents logical deployment of an application
internally it uses replica set to replicate the pods
can be updated or rollbacked using rollout commands
# get the list of deployments
>kubectlgetdeployments
>kubectlgetdeploy
# get details of selected deployment
>kubectldescribedeploy<deployname>
# delete deployment
>kubectldeletedeploy<deployname>
rollout
# restart the deployment using rollout# this will force deployment to load the new version from docker hub
>kubectlrolloutrestartdeployment<deployment-name>
# get the history of rollout
>kubectlrollouthistorydeployment<deployment-name>
# rollback to the older version (previous version)
>kubectlrolloutundodeployment<deployment-name>
# rollback to the specific older version
>kubectlrolloutundodeployment<deployment-name>--to-revision=<version-number>
# update the image tag (version)
>kubectlsetimagedeployment<deployment-name><container-name>=<newerversion>
# get the current status of rollout
>kubectlrolloutstatusdeployment<deployment-name>
persistent volumes
# get the list of persistent volumes
>kubectlgetpersistentvolumes
>kubectlgetpv
# create a pv
>kubectlapply-fpv.yaml
# get details of selected pv
>kubectldescribepv<pvname>
# delete a pv
>kubectldeletepv<pvname>
persistent volume claim
# get the list of pvc
>kubectlgetpvc
# get details of a selected pvc
>kubectldescribepvc<pvcname>
# delete a pvc
>kubectldeletepvc<pvcname>
metrics service
# apply the metrics server yaml
>kubectlapply-fhttps://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# the above url will deploy the metrics server in kube-system namespace# by default, this will not work# to fix the problem
>kubectleditdeploymentmetrics-server-nkube-system
# add the following line on line number 45
>--kubelet-insecure-tls=true# save and exit => esc :wq# get the top node usage
>kubectltopnodes
# get the top pods usage
>kubectltoppods
# get all the resources created in the kube-system namespace
>kubectlgetall-nkube-system
horizontal pod autoscaling
# get the list of hpa
>kubectlgethpa
# get details of selected hpa
>kubectldescribehpa<hpaname>
# delete a selected hpa
>kubectldeletehpa<hpaname>
job
# get the list of jobs
>kubectlgetjobs# get details of selected job
>kubectldescribejob<jobname>
# delete a selected job
>kubectldeletejob<jobname>
cron job
# get the list of cronjobs
>kubectlgetcronjobs
# get details of selected cronjob
>kubectldescribecronjob<cronjobname>
# delete a selected cronjob
>kubectldeletecronjob<cronjobname>