kubernetes cheat sheet

Kubernetes Cheat Sheet ve Kubernetes Nedir?

Kubernetes konteyner mimarisindeki uygulamaların devreye alınmasını, ölçeklenmesini ve izlenmesini otomatikleştiren bir açık kaynak çözümüdür.

Konteyner, temelindeki altyapıdan ayrı bir yazılımdır. Konteynerlerle, işletim sistemi seviyesine kadar her şey sanallaştırılır. Bu da bir uygulamanın, nerede çalışırsa çalışsın, aynı şekilde işlev göstereceği anlamına gelir.

Günümüzde çoğu konteyner bir Kubernetes platformunda çalışır. Kuruluşa göre: “Kubernetes konteyner merkezli bir yönetim ortamı sağlar. Kullanıcı iş yükleri adına bilgi işlem, ağ ve depolama altyapısını düzenler…ve altyapı sağlayıcıları genelinde taşınabilirlik sağlar.”

Kubernetes Resmi Web Adresi

Eğer Kubernetes Cluster kurulumu ile ilgileniyorsanız daha önceki yazıma bu bağlantıdan ulaşabilirsiniz. Kubernetes Cheat Sheet komutlarına aşağıdan ulaşabilirsiniz.”

Object Oluşturma Komutları

NameCommand
Create resourcekubectl apply -f ./<file_name>.yaml
Create from multiple fileskubectl apply -f ./<file_name_1>.yaml -f ./<file_name_2>.yaml
Create all files in directorykubectl apply -f ./<directory_name>
Create from urlkubectl apply -f https://<url>
Create podkubectl run <pod_name> –image <image_name>
Create pod, then expose it as servicekubectl run <pod_name> –image <image_name> –port <port> –expose
Create pod yaml filekubectl run <pod_name> –image image_name –dryrun=client -o yaml > <file_name>.yaml
Create deploymentkubectl create deployment <deployment_name> –image <image_name>
Create deployment yaml filekubectl create deployment <deployment_name> –image <image_name> –dry-run=client -o yaml > <file_name>.yaml
Create servicekubectl create service <service-type> <service_name> –tcp=<port:target_port>
Create service yaml filekubectl create service <service-type> <service_name> –tcp=<port:target_port> –dryrun=client -o yaml > <file_name>.yaml
Expose service from pod/deploymentkubectl expose deployment <pod/deployment_name> -type=<service-type> –port <port> –target-port <target_port>
Create config map from key-valuekubectl create configmap <configmap_name> –fromliteral=<key>:<value> –from-literal=<key>:<value>
Create config map from filekubectl create configmap <configmap_name> –fromfile=<file_name>
Create config map from env filekubectl create configmap <configmap_name> –from-envfile=<file_name>
Create secret from keyvaluekubectl create secret generic <secret_name> –fromliteral=<key>:<value> –from-literal=<key>:<value>
Create secret from filekubectl create secret generic <secret_name> –fromfile=<file_name>
Create jobkubectl create job <job_name> –image=<image_name>
Create job from cronjobkubectl create job <job_name> — from=cronjob/<cronjob-name>
Create cronjobkubectl create cronjob –image=<image_name> -schedule='<cron-syntax>’ — <command> <args>

Monitoring Komutları

NameCommand
Get node cpu and memory utilizationkubectl top node <node_name>
Get pod cpu and memory utilizationkubectl top pods <pod_name>

Node Komutları

NameCommand
Describe nodekubectl describe node <node_name>
Get node in yamlkubectl get node <node_name> -o yaml
Get nodekubectl get node <node_name>
Drain nodekubectl drain node <node_name>
Cordon nodekubectl cordon node <node_name>
Uncordon nodekubectl uncordon node <node_name>

Pod Komutları

NameCommand
Get podkubectl get pod <pod_name>
Get pod in yamlkubectl get pod <pod_name> -o yaml
Get pod wide informationkubectl get pod <pod_name> -o wide
Get pod with watchkubectl get pod <pod_name> -w
Edit podkubectl edit pod <pod_name>
Describe podkubectl describe pod <pod_name>
Delete podkubectl delete pod <pod_name>
Log podkubectl logs pod <pod_name>
Tail -f podkubectl logs pod -f <pod_name>
Execute into podkubectl exec -it pod <pod_name> /bin/bash
Running Temporary Imagekubectl run <pod_name> –image=curlimages/curl –rm -it -restart=Never — curl <destination>

Deployment Komutları

NameCommand
Get deploymentkubectl get deployment <deployment_name>
Get deployment in yamlkubectl get deployment <deployment_name> -o yaml
Get deployment wide informationkubectl get deployment <deployment_name> -o wide
Edit deploymentkubectl edit deployment <deployment_name>
Describe deploymentkubectl describe deployment <deployment_name>
Delete deploymentkubectl delete deployment <deployment_name>
Log deploymentkubectl logs deployment/deployment_name -f
Update imagekubectl set image deployment <deployment_name> <container_name>=<new_image_name>
Scale deployment with replicaskubectl scale deployment <deployment_name> –replicas <replicas>

Service Komutları

NameCommand
Get servicekubectl get service <service>
Get service in yamlkubectl get service <service> -o yaml
Get service wide informationkubectl get service <service> -o wide
Edit servicekubectl edit service <service>
Describe servicekubectl describe service <service>
Delete servicekubectl delete service <service>

Endpoints Komutları

NameCommand
Get endpointskubectl get endpoints <endpoints_name>

Ingress Komutları

NameCommand
Get ingresskubectl get ingress
Get ingress in yamlkubectl get ingress -o yaml
Get ingress wide informationkubectl get ingress -o wide
Edit ingresskubectl edit ingress <ingress_name>
Describe ingresskubectl describe ingress <ingress_name>
Delete ingresskubectl delete ingress <ingress_name>

DaemonSet Komutları

NameCommand
Get daemonsetkubectl get daemonset <daemonset_name>
Get daemonset in yamlkubectl get daemonset <daemonset_name> -o yaml
Edit daemonsetkubectl edit daemonset <daemonset_name>
Describe daemonsetkubectl describe daemonset <daemonset_name>
Delete daemonsetkubectl delete deployment <daemonset_name>

StatefulSet Komutları

NameCommand
Get statefulsetkubectl get statefulset <statefulset_name>
Get statefulset in yamlkubectl get statefulset <statefulset_name> -o yaml
Edit statefulsetkubectl edit statefulset <statefulset_name>
Describe statefulsetkubectl describe statefulset <statefulset_name>
Delete statefulesetkubectl delete statefulset <statefulset_name>

ConfigMaps Komutları

NameCommand
Get configmapkubectl get configmap <configmap_name>
Get configmap in yamlkubectl get configmap <configmap_name> -o yaml
Edit configmapkubectl edit configmap <configmap_name>
Describe configmapkubectl describe configmap <configmap_name>
Delete configmapkubectl delete configmap <configmap_name>

Secret Komutları

NameCommand
Get secretkubectl get secret <secret_name>
Get secret in yamlkubectl get secret <secret_name> -o yaml
Edit secretkubectl edit secret <secret_name>
Describe secretkubectl describe secret <secret_name>
Delete secretkubectl delete secret <secret_name>

Rollout Komutları

NameCommand
Restart deploymentkubectl rollout restart deployment <deployment_name>
Undo deployment with the latest revisionkubectl rollout undo deployment <deployment_name>
Undo deployment with specified revisionkubectl rollout undo deployment <deployment_name> –torevision <revision_number>
Get all revisions of deploymentkubectl rollout history deployment <deployment_name>
Get specified revision of deploymentkubectl rollout history deployment <deployment_name> -revision=<revision_number>

Job Komutları

NameCommand
Get jobkubectl get job <job_name>
Get job in yamlkubectl get job <job_name> -o yaml
Edit job in yamlkubectl edit job <job_name>
Describe jobkubectl describe job <job_name>
Delete jobkubectl delete job <job_name>

Cronjob Komutları

NameCommand
Get cronjobkubectl get cronjob cronjob_name
Get cronjob in yamlkubectl get cronjob <cronjob_name> -o yaml
Edit cronjobkubectl edit cronjob <cronjob_name>
Describe cronjobkubectl describe cronjob <cronjob_name>
Delete cronjobkubectl delete cronjob <cronjob_name>

Network Policy Komutları

NameCommand
Get networkpolicykubectl get networkpolicy <networkpolicy_name>
Get networkpolicy in yamlkubectl get networkpolicy <networkpolicy_name> o yaml
Get networkpolicy wide informationkubectl get networkpolicy <networkpolicy_name> o wide
Edit networkpolicykubectl edit networkpolicy <networkpolicy_name>
Describe networkpolicykubectl describe networkpolicy <networkpolicy_name>
Delete networkpolicykubectl delete networkpolicy <networkpolicy_name>

Labels and Selectors Komutları

NameCommand
Show labels of node,pod and deploymentkubectl get <node/pod/deployment> –showlabels
Attach labels to <node/pod/deployment>kubectl label <node/pod/deployment> <pod_name> <key>=<value>
Remove labels from <node/pod/deployment>kubectl label <node/pod/deployment> <pod_name> <key>-
Select node,pod and deployment by using labelskubectl get <node/pod/deployment> -l <key>=<value>