100% found this document useful (1 vote)
990 views2 pages

Kubernetes Cheat Sheet 04032019

This document provides a cheat sheet for common Kubernetes commands to view and interact with various Kubernetes resources like pods, deployments, services, secrets, and more. It lists commands for getting, describing, editing, deleting, scaling, and outputting resources. It also includes examples of creating deployments, running interactive pods, and getting help.

Uploaded by

sandeep patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
990 views2 pages

Kubernetes Cheat Sheet 04032019

This document provides a cheat sheet for common Kubernetes commands to view and interact with various Kubernetes resources like pods, deployments, services, secrets, and more. It lists commands for getting, describing, editing, deleting, scaling, and outputting resources. It also includes examples of creating deployments, running interactive pods, and getting help.

Uploaded by

sandeep patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Deployments ReplicaSets

Kubernetes Cheat $ k ubec t l get depl oy $ kubect l get r s

Sheet $ k ubec t l desc r i be depl oy


$ k ubec t l get depl oy - o wi de
$ kubect l descr i be r s
$ kubect l get r s - o wi de
$ k ubec t l get depl oy - o yaml $ kubect l get r s - o yaml
What is Kubernetes?
Services Roles
Kubernetes is a platform for managing containerized
workloads. Kubernetes orchestrates computing, $ k ubec t l get s vc $ kubect l get r ol es - - al l - namespaces
networking and storage to provide a seamless portability
$ k ubec t l desc r i be sv c $ kubect l get r ol es - - al l - namespaces - o yaml
across infrastructure providers.
$ k ubec t l get s vc - o wi de
$ k ubec t l get s vc - o y aml Secrets
Viewing Resource Information $ k ubec t l get s vc - - s how- l abel s
$ kubect l get s ecr et s
$ kubect l get s ecr et s - - al l - names pac es
Nodes DaemonSets $ kubect l get s ecr et s - o y aml
$ k ubec t l get no
$ k ubec t l get ds
$ k ubec t l get no - o wi de ConfigMaps
$ k ubec t l get ds - - al l - names pac es
$ k ubec t l des cr i be no $ kubect l get c m
$ k ubec t l desc r i be ds [ daemonset _name] - n
$ k ubec t l get no - o y aml [ namespace_name] $ kubect l get c m - - al l - namespaces
$ k ubec t l get node - - sel ect or =[ l abel _name] $ k ubec t l get ds [ ds_name] - n [ ns _name] - o $ kubect l get c m - - al l - namespaces - o yaml
$ k ubec t l get nodes - o y aml
j s onpat h=' { . i t ems[ * ] . st at us. addr es ses
Events Ingress
[ ?( @. t y pe==" Ext er nal I P" ) ] . addr ess} '
$ k ubec t l t op node [ node_name] $ kubect l get i ng
$ k ubec t l get event s
$ kubect l get i ng - - al l - names paces
Pods $ k ubec t l get event s - n kube- sy st em
$ k ubec t l get event s - w
$ k ubec t l get po PersistentVolume
$ k ubec t l get po - o wi de Logs $ kubect l get pv
$ k ubec t l des cr i be po
$ k ubec t l l ogs [ pod_name] $ kubect l descr i be pv
$ k ubec t l get po - - show- l abel s
$ k ubec t l get po - l app=ngi nx $ k ubec t l l ogs - - si nc e=1h [ pod_name]
$ k ubec t l l ogs - - t ai l =20 [ pod_name]
PersistentVolumeClaim
$ k ubec t l get po - o y aml
$ k ubec t l get pod [ pod_name] - o yaml $ k ubec t l l ogs - f - c [ cont ai ner _name] $ kubect l get pvc
- - expor t [ pod_name]
$ kubect l descr i be pvc
$ k ubec t l get pod [ pod_name] - o yaml $ k ubec t l l ogs [ pod_name] > pod. l og
- - expor t > nameof f i l e. yaml
Service Accounts
$ k ubec t l get pods - - f i el d- s el ect or
st at us. phase=Runni ng $ k ubec t l get s a
Namespaces $ k ubec t l get s a - o y aml
$ k ubec t l get s er vi ceacc ount s def aul t - o
$ k ubec t l get ns y aml > . / s a. yaml
$ k ubec t l get ns - o y aml
$ k ubec t l des cr i be ns
$ k ubec t l r epl ace s er v i c eacc ount def aul t - f
. / s a. yaml
http://linuxacademy.com
Deployments/Namespaces Creating a Deployment
Kubernetes Cheat $ k ubec t l edi t depl oy [ depl oy _name] $ kubec t l c r eat e - f [ name_of _f i l e]

Sheet page 2
$ k ubec t l del et e depl oy [ depl oy _name]
$ k ubec t l ex pos e depl oy [ depl oy _name]
$ kubec t l appl y - f [ name_of _f i l e]
$ kubec t l c r eat e depl oy [ depl oy_name]
- - por t =80 - - t y pe=NodePor t - - i mage=ngi nx
Viewing Resource Information (cont.) $ k ubec t l sc al e depl oy [ depl oy_name]
- - r epl i c as =5 Interactive Pod
StorageClass $ k ubec t l del et e ns $ kubec t l r un [ pod_name] - - i mage=busybox
$ k ubec t l edi t ns [ ns _name] - - r m - i t - - r es t ar t =Never - - sh
$ k ubect l get s c
$ k ubect l get s c - o yaml Services Output YAML to a File

$ k ubec t l edi t sv c [ s v c_name] $ k ubect l cr eat e depl oy [ depl oy _name]


Multiple Resources - - i mage=ngi nx - - dr y- r un - o yaml >
$ k ubec t l del et e sv c [ sv c_name] depl oy . yaml
$ k ubect l get s vc, po $ k ubect l get po [ pod_name] - o yaml - - expor t
$ k ubect l get depl oy , no
DaemonSets
> pod. yaml
$ k ubect l get al l $ k ubec t l edi t ds [ ds _name] - n kube- sy st em
Getting Help
$ k ubect l get al l - - al l - namespaces $ k ubec t l del et e ds [ ds_name]
$ k ubect l - h
Service Accounts $ k ubect l cr eat e - h
Changing Resource Attributes $ k ubec t l edi t sa [ sa_name] $ k ubect l r un - h
$ k ubec t l del et e sa [ s a_name] $ k ubect l expl ai n depl oy . spec
Taint
$ k ubect l t ai nt [ node_name] [ t ai nt _name] Annotate
Requests
$ k ubec t l annot at e po [ pod_name]
Labels [ annot at i on]
API Call
$ k ubec t l l abel [ node_name] di sk t ype=ssd $ k ubec t l annot at e no [ node_name]
$ k ubect l get - - r aw / api s/ met r i cs. k8s. i o/
$ k ubr ec t l l abel [ pod_name] env=pr od

Adding Resources
Cordon/Uncordon Cluster Info
$ k ubec t l c or don [ node_name]
Creating a Pod $ k ubect l conf i g
$ k unec t l uncor don [ node_name] $ k ubec t l cr eat e - f [ name_of _f i l e] $ k ubect l cl ust er - i nf o
$ k ubec t l appl y - f [ name_of _f i l e] $ k ubect l get component s t at uses
Drain
$ k ubec t l r un [ pod_name] - - i mage=ngi nx
$ k ubect l dr ai n [ node_name] - - r es t ar t =Never
$ k ubec t l r un [ pod_name]
- - gener at or =r un- pod/ v 1 - - i mage=ngi nx
Nodes/Pods
$ k ubec t l r un [ pod_name] - - i mage=ngi nx
$ k ubec t l del et e node [ node_name] - - r es t ar t =Never

$ k ubec t l del et e pod [ pod_name] Creating a Service


$ k ubec t l edi t node [ node_name]
$ k ubec t l edi t pod [ pod_name]
$ k ubec t l cr eat e sv c nodepor t [ sv c _name]
- - t cp=8080: 80
http://linuxacademy.com

You might also like