Skip to content

Kubectl commands

  1. Introduction
  2. Kubectl Cheat Sheets
  3. Kubectl aliases
  4. Kubectl explain
  5. Kubectl example
  6. Kubectl Autocomplete
  7. kubectl exec
  8. kubectl scale
  9. kubectl debug
  10. List all resources and sub resources that you can constrain with RBAC
  11. Copy a configMap in kubernetes between namespaces
  12. Copy secrets in kubernetes between namespaces
  13. Export resources with kubectl and python
  14. Buildkit CLI for kubectl a drop in replacement for docker build
  15. Kubectl Alternatives
    1. Manage Kubernetes (K8s) objects with Ansible Kubernetes Module
    2. Jenkins Kubernetes Plugins
  16. Videos
  17. Tweets

Introduction

Kubectl Cheat Sheets

Kubectl aliases

Kubectl explain

for r in $(kubectl api-resources|grep -v ^N|awk '{print $1}');do kubectl explain $r --recursive;done

Kubectl example

Kubectl Autocomplete

source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.

You can also use a shorthand alias for kubectl that also works with completion:

alias k=kubectl
complete -F __start_kubectl k

kubectl exec

  • containiq.com: Using kubectl exec | Shell Commands & Examples kubectl exec lets you start a shell session to containers running in your Kubernetes cluster. It’s a bit like SSH for Kubernetes. Here’s what you need to know to use this command as part of your cluster management procedures, including the cases where it makes the most sense.
  • itnext.io: Connect to containers using Kubectl Exec In this article, we will look at the kubectl exec command to show how to get a shell into a running container in your Kubernetes (K8S) cluster, and how to run individual commands on a container with some useful examples.
  • goteleport.com: kubectl exec vs SSH This article compares kubectl exec and SSH and discusses their strengths and weaknesses

kubectl scale

kubectl debug

List all resources and sub resources that you can constrain with RBAC

  • kind of a handy way to see all thing things you can affect with Kubernetes RBAC. This will list all resources and sub resources that you can constrain with RBAC. If you want to see just subresources append “| grep {name}/”:
kubectl get --raw /openapi/v2  | jq '.paths | keys[]'

Copy a configMap in kubernetes between namespaces

  • Copy a configMap in kubernetes between namespaces with deprecated “–export” flag:
kubectl get configmap --namespace=<source> <configmap> --export -o yaml | sed "s/<source>/<dest>/" | kubectl apply --namespace=<dest> -f -
kubectl get configmap <configmap-name> --namespace=<source-namespace> -o yaml | sed ‘s/namespace: <from-namespace>/namespace: <to-namespace>/’ | kubectl create -f

Copy secrets in kubernetes between namespaces

kubectl get secret <secret-name> --namespace=<source> -o yaml | sed ‘s/namespace: <from-namespace>/namespace: <to-namespace>/’ | kubectl create -f

Export resources with kubectl and python

Buildkit CLI for kubectl a drop in replacement for docker build

Kubectl Alternatives

Manage Kubernetes (K8s) objects with Ansible Kubernetes Module

Jenkins Kubernetes Plugins

Videos

Click to expand!

Tweets

Click to expand!