Uploaded by Shady Said

Kubernetes-Cheat-Sheet 07182019

advertisement
Kubernetes Cheat
Sheet
What is Kubernetes?
Kubernetes is a platform for managing containerized
workloads. Kubernetes orchestrates computing,
networking and storage to provide a seamless portability
across infrastructure providers.
Deployments
ReplicaSets
$ k ubec t l get depl oy
$ kubect l get r s
$ k ubec t l desc r i be depl oy
$ kubect l descr i be r s
$ k ubec t l get depl oy - o wi de
$ kubect l get r s - o wi de
$ k ubec t l get depl oy - o yaml
$ kubect l get r s - o yaml
Services
Roles
$ k ubec t l get s vc
$ kubect l get r ol es - - al l - namespaces
$ k ubec t l desc r i be sv c
$ kubect l get r ol es - - al l - namespaces - o yaml
$ k ubec t l get s vc - o wi de
$ k ubec t l get s vc - o y aml
Viewing Resource Information
Nodes
$ k ubec t l get no
$ k ubec t l get no - o wi de
$ k ubec t l des cr i be no
$ k ubec t l get no - o y aml
$ k ubec t l get node - - sel ect or =[ l abel _name]
$ k ubec t l get nodes - o
j s onpat h=' { . i t ems[ * ] . st at us. addr es ses
[ ?( @. t y pe==" Ext er nal I P" ) ] . addr ess} '
$ 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
DaemonSets
$ kubect l get s ecr et s - o y aml
$ k ubec t l get ds
ConfigMaps
$ k ubec t l get ds - - al l - names pac es
$ k ubec t l desc r i be ds [ daemonset _name] - n
[ namespace_name]
$ kubect l get c m
$ k ubec t l get ds [ ds_name] - n [ ns _name] - o
y aml
$ kubect l get c m - - al l - namespaces - o yaml
Events
$ k ubec t l t op node [ node_name]
$ k ubec t l get event s
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
$ k ubec t l get po - o wi de
Secrets
$ kubect l get c m - - al l - namespaces
Ingress
$ kubect l get i ng
$ kubect l get i ng - - al l - names paces
PersistentVolume
Logs
$ kubect l get pv
$ k ubec t l get po - - show- l abel s
$ k ubec t l l ogs [ pod_name]
$ kubect l descr i be pv
$ 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 get po - o y aml
$ k ubec t l l ogs - - t ai l =20 [ pod_name]
$ k ubec t l get pod [ pod_name] - o yaml
- - expor t
$ k ubec t l l ogs - f - c [ cont ai ner _name]
[ pod_name]
$ k ubec t l get pod [ pod_name] - o yaml
- - expor t > nameof f i l e. yaml
$ k ubec t l l ogs [ pod_name] > pod. l og
$ k ubec t l des cr i be po
$ k ubec t l get pods - - f i el d- s el ect or
st at us. phase=Runni ng
$ kubect l descr i be pvc
$ k ubec t l get s a
$ k ubec t l get s a - o y aml
$ k ubec t l get ns
$ k ubec t l get s er vi ceacc ount s def aul t - o
y aml > . / s a. yaml
$ k ubec t l des cr i be ns
$ kubect l get pvc
Service Accounts
Namespaces
$ k ubec t l get ns - o y aml
PersistentVolumeClaim
$ 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
$ 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]
$ k ubec t l del et e depl oy [ depl oy _name]
$ kubec t l appl y - f [ name_of _f i l e]
$ k ubec t l ex pos e depl oy [ depl oy _name]
- - por t =80 - - t y pe=NodePor t
$ kubec t l c r eat e depl oy [ depl oy_name]
- - 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
Kubernetes Cheat
Sheet
page 2
$ k ubec t l edi t ns [ ns _name]
$ kubec t l r un [ pod_name] - - i mage=busybox
- - r m - i t - - r es t ar t =Never - - sh
$ k ubect l get s c - o yaml
Services
Output YAML to a File
Multiple Resources
$ k ubec t l edi t sv c [ s v c_name]
$ k ubect l cr eat e depl oy [ depl oy _name]
- - i mage=ngi nx - - dr y- r un - o yaml >
depl oy . yaml
$ k ubect l get s c
$ k ubect l get s vc, po
$ k ubec t l del et e sv c [ sv c_name]
DaemonSets
$ k ubect l get po [ pod_name] - o yaml - - expor t
> pod. yaml
$ k ubect l get al l
$ k ubec t l edi t ds [ ds _name] - n kube- sy st em
$ k ubect l get al l - - al l - namespaces
$ k ubec t l del et e ds [ ds_name]
Getting Help
$ k ubect l get depl oy , no
$ k ubect l - h
Changing Resource Attributes
Taint
Service Accounts
$ k ubect l cr eat e - h
$ 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
$ k ubect l t ai nt [ node_name] [ t ai nt _name]
Annotate
Labels
$ k ubec t l annot at e po [ pod_name]
[ annot at i on]
$ k ubec t l l abel [ node_name] di sk t ype=ssd
$ k ubec t l annot at e no [ node_name]
$ k ubec t l c or don [ node_name]
API Call
$ 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
Cordon/Uncordon
Requests
Adding Resources
Creating a Pod
Cluster Info
$ k ubect l conf i g
$ k ubec 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
Drain
$ k ubec t l appl y - f [ name_of _f i l e]
$ k ubect l get component s t at uses
$ k ubect l dr ai n [ node_name]
$ k ubec t l r un [ pod_name] - - i mage=ngi nx
- - r es t ar t =Never
Nodes/Pods
$ k ubec t l r un [ pod_name]
- - gener at or =r un- pod/ v 1 - - i mage=ngi nx
$ k ubec t l del et e node [ node_name]
$ k ubec t l r un [ pod_name] - - i mage=ngi nx
- - 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
Download