Kubectl commands
- Introduction
- Kubectl Cheat Sheets
- Kubectl aliases
- Kubectl explain
- Kubectl example
- Kubectl Autocomplete
- kubectl exec
- kubectl scale
- kubectl debug
- List all resources and sub resources that you can constrain with RBAC
- Copy a configMap in kubernetes between namespaces
- Copy secrets in kubernetes between namespaces
- Export resources with kubectl and python
- Buildkit CLI for kubectl a drop in replacement for docker build
- Kubectl Alternatives
- Videos
- Tweets
Introduction
- itnext.io: Boosting your kubectl productivity
- medium: 4 Simple Kubernetes Terminal Customizations to Boost Your Productivity
- medium: Ready-to-use commands and tips for kubectl
- medium: Be fast with Kubectl 1.19 CKAD/CKA 🌟 Collection of the fastest ways to create k8s resources using kubectl ≥ 1.18
- developers.redhat.com: Kubectl: Developer tips for the Kubernetes command line 🌟
- ibm.com: 8 Kubernetes Tips and Tricks 🌟 Most of the tips given below are using kubectl, a powerful command-line tool that allows you to execute commands against Kubernetes clusters.
- Set default namespaces
- Helpful aliases to save time
- YAML editing with vi
- Create YAML from kubectl commands
- Switching between Kubernetes namespaces
- Shell auto-completion
- Viewing resource utilization
- Extend kubectl and create your own commands using raw outputs
- pixelstech.net: Update & Delete Kubernetes resources in one-line command
- opensource.com: 5 useful ways to manage Kubernetes with kubectl Learn kubectl to enhance how you interact with Kubernetes.
- hackerxone.com: How to Manage Single & Multiple Kubernetes Clusters using kubectl & kubectx in Linux
- Get kubectl access to your private cluster from anywhere This tutorial shows you how to expose your private Kubernetes API server to the Internet, so that you can manage your cluster from anywhere, just like you would with a cloud offering.
- medium: One CKA/CKAD/CKS requirement: Mastering Kubectl
- medium: Replication Controller Vs ReplicaSets in Kubernetes Learn why we need replication and how replication works in Kubernetes. Scale the application using the kubectl scale command.
- dev.to: Open a command prompt in a Kubernetes cluster This starts up a pod (in the default namespace by default) and opens a command line in the given container. As I’m running as root, I can install anything I need for debugging and testing right in my cluster.
- akhilsharma.work: Checking Kubernetes API Calls using kubectl In order to interact, we can simply use
kubectl
. Just add verbose logging level of 8+ and you will get the API calls!kubectl get pods -v=8
kubectl create job my-job --image=busybox --dry-run=server -v8
- cloudsavvyit.com: How to Restart Kubernetes Pods with Kubectl
- technos.medium.com: How kubectl apply command works?
- blogs.nakam.org: What Happens When? K8s Edition 🌟 What happens when you do kubectl create deploy nginx –image=nginx –replicas=3
- inlets.dev: Fixing the Developer Experience of Kubernetes Port Forwarding This article shows you some of the frustrations of using kubectl for port-forwarding and how to fix the developer experience.
- medium.com/swlh: Break Down Kubernetes Server-Side Apply (Advanced kubectl) 🌟 Are you already using the SSA? Do you know the difference between CSA and SSA?
- containiq.com: Kubectl Config Set-Context | Tutorial and Best Practices Kubernetes comes with many tools to help you manage your clusters, including kubectl set-context. In this guide, you’ll learn how to use this command to manipulate contexts in your kubeconfig file, as well as best practices for doing so.
- blog.devgenius.io: K8s — Manage Multiple Clusters Using kubectl at Scale Manage multiple K8s clusters efficiently using kubectl
- itnext.io: How to Restart Kubernetes Pods With Kubectl 🌟 A pod is the smallest unit in Kubernetes (K8S). They should run until they are replaced by a new deployment. Because of this, there is no way to restart a pod, instead, it should be replaced.
- awstip.com: Kubernetes — Creating deployments via command line and with YAML files
- superbrothers/zsh-kubectl-prompt 🌟 Display information about the kubectl current context and namespace in zsh prompt.
- medium.com/@emmaliaocode: kubectl create vs kubectl apply. What’s the difference?
- hidetatz/kubecolor 🌟 colorizes kubectl output
- medium.com/codex: Kubectl Output 101 Cheatsheet & examples of using kubectl get -o
- lovethepenguin.com: Kubernetes: common pod operations
- medium.com/geekculture: kubectl — Best Practices
- learnitguide.net: How to Create ConfigMap from Properties File Using K8s Client
- shardul.dev: Most Useful kubectl Plugins In this article, you will have a look at the following kubectl plugins:
- neat
- view-secret
- access-matrix
- blame
- df-pv
- gke-outdated
- howtogeek.com: Getting Started With Kubectl to Manage Kubernetes Clusters Kubernetes is a container orchestration engine that lets you deploy containerised workloads in a scalable way.
- medium.com/@jake.page91: The guide to kubectl I never had
- itnext.io: Kubernetes Contexts: Complete Guide for Developers An introduction to Kubeconfig and Contexts. It’s finally time to understand how kubectl connects to Kubernetes.
Kubectl Cheat Sheets
Kubectl aliases
- ahmetb/kubectl-aliases Programmatically generated handy kubectl aliases. This repository contains a script to generate hundreds of convenient shell aliases for kubectl, so you no longer need to spell out every single command and –flag over and over again
- blog.devgenius.io: Daily useful Kubernetes aliases
Kubectl explain
- kubectl explain
- itnext.io: Using ‘kubectl explain’ for Custom Resources Goal: Explore if ‘kubectl explain’ can be used to discover static information about Custom Resources
for r in $(kubectl api-resources|grep -v ^N|awk '{print $1}');do kubectl explain $r --recursive;done
Kubectl example
- github.com/trstringer/kubectl-example kubectl plugin to dump example helper resource templates
Kubectl Autocomplete
- Kubectl Autocomplete
- kubectl Shell Autocomplete
- Kubernetes productivity tips and tricks 🌟
- complete-alias Automagical shell alias completion.
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
- containiq.com: Using Kubectl Scale | Tutorial and Best Practices kubectl scale is one of the many tools that helps you manage your Kubernetes deployments. In this article, you’ll learn how this tool can be used, as well as best practices for use.
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 -
- Flag export deprecated in kubernetes 1.14. Instead following command can be used:
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
- Export resources with zoidbergwill/export.sh, by zoidbergwill
Buildkit CLI for kubectl a drop in replacement for docker build
- container-registry.com: Lifting Developers’ Productivity 🌟 With BuildKit CLI for kubectl a drop in replacement for docker build. In this post, you will learn how to build container images with BuildKit CLI for kubectl (a replacement for the
docker build
command) - vmware-tanzu/buildkit-cli-for-kubectl (kubectl plugin) BuildKit CLI for kubectl is a tool for building container images with your Kubernetes cluster.
Kubectl Alternatives
Manage Kubernetes (K8s) objects with Ansible Kubernetes Module
Jenkins Kubernetes Plugins
Videos
Click to expand!
Tweets
Click to expand!
TIL: How to create Kubernetes manifests real quick 🤯
— Ivan Velichko (@iximiuz) January 17, 2022
Use kubectl create –dry-run=client -o yaml
Example:<br>kubectl create deployment foo \<br> --image=nginx:1.21 \<br> --dry-run=client \<br> -o yaml<br>