If you’re like me, you may have those moments where you’re at the terminal, hands hovering over your keyboard, and … nothing. I always seem to freeze up and probably rely too much on bash history. (The up arrow is my friend.)While learning Kubernetes, I ended up posting 14 or 15 sticky notes on my monitor to help me in those moments — but after a while, I could barely read what was on the screen. So finally, I created one small, easy-to-read piece of paper to reference when I, or you, get stuck. This Kubernetes Cheat Sheet is meant to get you started performing commands in Kubernetes and provide you with all the basic commands at a quick glance. (Check out the downloadable asset below!)Command ResultsSome of the commands on this cheat sheet might not return any results, but have no fear! See below for some resources you can create, then quickly turn around and run the commands in your cheat sheet to alter your resources any way you wish!Let’s start with pods. Here is the YAML for a basic busybox pod:
apiVersion: v1kind: Podmetadata:name: busyboxspec:containers:- image: busybox:1.28.4command:- sleep- "3600"name: busyboxrestartPolicy: Always
Learn more about YAML here.Create the pod with this command:
kubectl create -f busybox.yaml
Use this command to create a deployment:
kubectl run nginx --image=nginx
Use this command to create a service from the deployment above:
kubectl expose deployment nginx --port=80 --type=NodePort
Sign up for a free community account today and check out these free courses: Kubernetes Essentials and Beginner’s Guide to Containers and Orchestration to learn more about Kubernetes!Here is the YAML for a simple persistent volume using local storage from the node:
apiVersion: v1kind: PersistentVolumemetadata:name: data-pvnamespace: webspec:storageClassName: local-storagecapacity:storage: 1GiaccessModes:- ReadWriteOncehostPath:path: /mnt/data
Use the following command to create the persistent volume:
kubectl apply -f my-pv.yaml
Here is the YAML for a simple ConfigMap:
apiVersion: v1kind: ConfigMapmetadata:name: my-config-mapdata:myKey: myValueanotherKey: anotherValue
Use the following command to create the ConfigMap:
kubectl apply -f configmap.yaml
Here is the YAML for a secret:
apiVersion: v1kind: Secretmetadata:name: my-secretstringData:myKey: myPassword
Use this command to create the secret:
kubectl apply -f secret.yaml
Here is the YAML for a service account:
apiVersion: v1kind: ServiceAccountmetadata:name: acrnamespace: defaultsecrets:- name: acr
Use this command to create the service account:
kubectl apply -f serviceaccount.yaml
Download Now!
This should be enough to get you started! I’ve also created this PDF for you to download and keep next to you for reference! If you enjoyed these exercises and following along with the commands, check out the brand new Cloud Native Certified Kubernetes Administrator (CKA) course on Linux Academy to dig deeper into Kubernetes! Or check out these additional free resources: