Kubernetes Cheatsheet Creating Objects:-: Name Command

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6
At a glance
Powered by AI
The document provides a cheatsheet of common Kubernetes commands to create and manage different Kubernetes objects like pods, deployments, services etc.

The main object types that can be created are pods, deployments, services, configmaps, secrets etc. using commands like kubectl run, kubectl create deployment etc.

Commands like kubectl top node/pod, kubectl describe node/pod, kubectl logs are used to monitor nodes and pods for CPU/memory utilization and logs.

Kubernetes Cheatsheet

Creating Objects:-
Name Command
Create resource kubectl apply -f ./<file_name>.yaml
kubectl apply -f ./<file_name_1>.yaml -f
Create from multiple files
./<file_name_2>.yaml
Create all files in directory kubectl apply -f ./<directory_name>
Create from url kubectl apply -f https://<url>
Create pod kubectl run <pod_name> --image <image_name>
Create pod, then expose it kubectl run <pod_name> --image <image_name> --port
as service <port> --expose
kubectl run <pod_name> --image image_name --dry-
Create pod yaml file
run=client -o yaml > <file_name>.yaml
kubectl create deployment <deployment_name> --image
Create deployment
<image_name>
kubectl create deployment <deployment_name> --image
Create deployment yaml
<image_name> --dry-run=client -o yaml >
file
<file_name>.yaml
kubectl create service <service-type>
Create service
<service_name> --tcp=<port:target_port>
kubectl create service <service-type>
Create service yaml file <service_name> --tcp=<port:target_port> --dry-
run=client -o yaml > <file_name>.yaml
kubectl expose deployment <pod/deployment_name> --
Expose service from
type=<service-type> --port <port> --target-port
pod/deployment
<target_port>
Create config map from kubectl create configmap <configmap_name> --from-
key-value literal=<key>:<value> --from-literal=<key>:<value>
kubectl create configmap <configmap_name> --from-
Create config map from file
file=<file_name>
Create config map from env kubectl create configmap <configmap_name> --from-env-
file file=<file_name>
Create secret from key- kubectl create secret generic <secret_name> --from-
value literal=<key>:<value> --from-literal=<key>:<value>
kubectl create secret generic <secret_name> --from-
Create secret from file
file=<file_name>

https://www.facebook.com/groups/devopsg/
Name Command
Create job kubectl create job <job_name> --image=<image_name>
kubectl create job <job_name> --
Create job from cronjob
from=cronjob/<cronjob-name>
kubectl create cronjob --image=<image_name> --
Create cronjob
schedule='<cron-syntax>' -- <command> <args>

Monitoring Usage Commands:-


Name Command
Get node cpu and memory utilization kubectl top node <node_name>
Get pod cpu and memory utilization kubectl top pods <pod_name>

Node Commands:-
Name Command
Describe node kubectl describe node <node_name>
Get node in yaml kubectl get node <node_name> -o yaml
Get node kubectl get node <node_name>
Drain node kubectl drain node <node_name>
Cordon node kubectl cordon node <node_name>
Uncordon node kubectl uncordon node <node_name>

Pod Commands:-
Name Command
Get pod kubectl get pod <pod_name>
Get pod in yaml kubectl get pod <pod_name> -o yaml
Get pod wide
kubectl get pod <pod_name> -o wide
information
Get pod with watch kubectl get pod <pod_name> -w
Edit pod kubectl edit pod <pod_name>
Describe pod kubectl describe pod <pod_name>
Delete pod kubectl delete pod <pod_name>
Log pod kubectl logs pod <pod_name>
Tail -f pod kubectl logs pod -f <pod_name>

https://www.facebook.com/groups/devopsg/
Name Command
Execute into pod kubectl exec -it pod <pod_name> /bin/bash
Running Temporary kubectl run <pod_name> --image=curlimages/curl --rm -it --
Image restart=Never -- curl <destination>

Deployment Commands:-
Name Command
Get deployment kubectl get deployment <deployment_name>
Get deployment in
kubectl get deployment <deployment_name> -o yaml
yaml
Get deployment
kubectl get deployment <deployment_name> -o wide
wide information
Edit deployment kubectl edit deployment <deployment_name>
Describe
kubectl describe deployment <deployment_name>
deployment
Delete deployment kubectl delete deployment <deployment_name>
Log deployment kubectl logs deployment/deployment_name -f
kubectl set image deployment <deployment_name>
Update image
<container_name>=<new_image_name>
Scale deployment kubectl scale deployment <deployment_name> --replicas
with replicas <replicas>

Service Commands:-
Name Command
Get service kubectl get service <service>
Get service in yaml kubectl get service <service> -o yaml
Get service wide information kubectl get service <service> -o wide
Edit service kubectl edit service <service>
Describe service kubectl describe service <service>
Delete service kubectl delete service <service>

Endpoints Commands:-
Name Command
Get endpoints kubectl get endpoints <endpoints_name>

https://www.facebook.com/groups/devopsg/
Ingress Commands:-
Name Command
Get ingress kubectl get ingress
Get ingress in yaml kubectl get ingress -o yaml
Get ingress wide information kubectl get ingress -o wide
Edit ingress kubectl edit ingress <ingress_name>
Describe ingress kubectl describe ingress <ingress_name>
Delete ingress kubectl delete ingress <ingress_name>

DaemonSet Commands:-
Name Command
Get daemonset kubectl get daemonset <daemonset_name>
Get daemonset in yaml kubectl get daemonset <daemonset_name> -o yaml
Edit daemonset kubectl edit daemonset <daemonset_name>
Describe daemonset kubectl describe daemonset <daemonset_name>
Delete daemonset kubectl delete deployment <daemonset_name>

StatefulSet Commands:-
Name Command
Get statefulset kubectl get statefulset <statefulset_name>
Get statefulset in yaml kubectl get statefulset <statefulset_name> -o yaml
Edit statefulset kubectl edit statefulset <statefulset_name>
Describe statefulset kubectl describe statefulset <statefulset_name>
Delete statefuleset kubectl delete statefulset <statefulset_name>

ConfigMaps Commands:-
Name Command
Get configmap kubectl get configmap <configmap_name>
Get configmap in yaml kubectl get configmap <configmap_name> -o yaml
Edit configmap kubectl edit configmap <configmap_name>
Describe configmap kubectl describe configmap <configmap_name>
Delete configmap kubectl delete configmap <configmap_name>

https://www.facebook.com/groups/devopsg/
Secret Commands:-
Name Command
Get secret kubectl get secret <secret_name>
Get secret in yaml kubectl get secret <secret_name> -o yaml
Edit secret kubectl edit secret <secret_name>
Describe secret kubectl describe secret <secret_name>
Delete secret kubectl delete secret <secret_name>

Rollout Commands:-
Name Command
Restart deployment kubectl rollout restart deployment <deployment_name>
Undo deployment with
kubectl rollout undo deployment <deployment_name>
the latest revision
Undo deployment with kubectl rollout undo deployment <deployment_name> --to-
specified revision revision <revision_number>
Get all revisions of
kubectl rollout history deployment <deployment_name>
deployment
Get specified revision of kubectl rollout history deployment <deployment_name> --
deployment revision=<revision_number>

Job Commands:-
Name Command
Get job kubectl get job <job_name>
Get job in yaml kubectl get job <job_name> -o yaml
Edit job in yaml kubectl edit job <job_name>
Describe job kubectl describe job <job_name>
Delete job kubectl delete job <job_name>

Cronjob Commands:-
Name Command
Get cronjob kubectl get cronjob cronjob_name
Get cronjob in yaml kubectl get cronjob <cronjob_name> -o yaml

https://www.facebook.com/groups/devopsg/
Name Command
Edit cronjob kubectl edit cronjob <cronjob_name>
Describe cronjob kubectl describe cronjob <cronjob_name>
Delete cronjob kubectl delete cronjob <cronjob_name>

Network Policy Commands:-


Name Command
Get networkpolicy kubectl get networkpolicy <networkpolicy_name>
kubectl get networkpolicy <networkpolicy_name> -
Get networkpolicy in yaml
o yaml
Get networkpolicy wide kubectl get networkpolicy <networkpolicy_name> -
information o wide
Edit networkpolicy kubectl edit networkpolicy <networkpolicy_name>
kubectl describe networkpolicy
Describe networkpolicy <networkpolicy_name>
kubectl delete networkpolicy
Delete networkpolicy <networkpolicy_name>

Labels and Selectors Commands:-


Name Command
Show labels of node,pod and kubectl get <node/pod/deployment> --show-
deployment labels
Attach labels to kubectl label <node/pod/deployment>
<node/pod/deployment> <pod_name> <key>=<value>
Remove labels from kubectl label <node/pod/deployment>
<node/pod/deployment> <pod_name> <key>-
Select node,pod and deployment by kubectl get <node/pod/deployment> -l
using labels <key>=<value>

https://www.facebook.com/groups/devopsg/

You might also like