kubernetes cheat sheet
Share on facebook
Share on twitter
Share on linkedin

Kubernetes Cheat Sheet

Chad Crowell
Chad Crowell

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!Kubernetes Cheat Sheet 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:

Recommended

Get more insights, news, and assorted awesomeness around all things cloud learning.

Get Started
Who’s going to be learning?
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout