DEV Community

Cover image for A Kubernetes memory aid for beginners
Florian Baba
Florian Baba

Posted on

1 2

A Kubernetes memory aid for beginners

Hello!
Since I'm a Kube beginner, I gradually started writing this memory aid.

It's not exhaustive at all, but it's a start :)
I hope it helps.

You'll need this alias for all the listed cmd: alias k='kubectl'

Contexts

List contexts (and show the current one)

k config get-contexts
Enter fullscreen mode Exit fullscreen mode

Switch context

k config use-context <CONTEXT_NAME>
Enter fullscreen mode Exit fullscreen mode

Pods

List pods

k get pod
Enter fullscreen mode Exit fullscreen mode

Delete a pod

k delete pod <POD-ID>
Enter fullscreen mode Exit fullscreen mode

Show pod details (and the events linked to the pod)

k describe pod <POD-ID>
Enter fullscreen mode Exit fullscreen mode

Download a file from a pod

k cp <POD-ID>:<POD_FILE_PATH> <LOCAL_PATH>
Enter fullscreen mode Exit fullscreen mode

Containers

Connect to a container using sh or bash

k exec -it <POD-ID> -c <CONTAINER-NAME> <sh|bash>
Enter fullscreen mode Exit fullscreen mode

Logs

Show logs of a container

k logs <POD-ID> <CONTAINER-NAME> -f
Enter fullscreen mode Exit fullscreen mode

Show all the logs of a deployment

k logs -f deployment/<DEPLOYMENT-NAME> --all-containers=true
Enter fullscreen mode Exit fullscreen mode

Events

List events sorted by timestamp

k get event --sort-by .lastTimestamp
Enter fullscreen mode Exit fullscreen mode

Secrets

Show secrets with age

k get externalsecrets
Enter fullscreen mode Exit fullscreen mode

Deploys

List deploys on a cluster

k get deploy
Enter fullscreen mode Exit fullscreen mode

List deploys on a cluster, with details

kubectl get deploy -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,VERSION:.metadata.labels.version
Enter fullscreen mode Exit fullscreen mode

Show deploy status

k rollout status deploy/<DEPLOY-NAME>
Enter fullscreen mode Exit fullscreen mode

Scale

Define the number of replicas

k scale deploy/<DEPLOY-NAME> --replicas=2
Enter fullscreen mode Exit fullscreen mode

Show replicas sets

k get rs
Enter fullscreen mode Exit fullscreen mode

Cron

Show cron jobs

k get cronjobs
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay