Useful Kubernetes
Useful commands, shortcuts, configs and setups for Kubernetes
Shell Setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
alias k="kubectl"
alias v="vim"
alias kgp="kubectl get pods"
alias kgn="kubectl get nodes"
# usage: k run nginx --image=nginx $dr > nginx.yaml
export dr="--dry-run=client -oyaml"
# usage: k delete pod nginx $now
export now="--force --grace-period=0"
# For setting default namespace
# usage: ns kube-system
function ns () {
kubectl config set-context --current --namespace=$1
}
VIM Setup
1
2
3
4
# nu = set line numbers
# ts = tab stop and sw = shiftwidth - use 2 spaces instead of 1 for tab
# ai = autoindent on newline
set nu ai ts=2 sw=2 expandtab
Shortcuts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Create a yaml file for creating an nginx pod which uses the nginx image
k run nignix --image nginx $dr > pod_template.yaml
# Creating pods
k run messaging-pod --image=redis:alpine --labels=tier=msg
# Create namespace
k create ns my-new-namespace
# Get existing pods current yaml manifest
k get pod <pod-name> --export -o yaml
# Create a pod using a yaml manifest
k apply -f orange.yaml
# Expose a given port on a pod
k expose pod messaging --port=6379 --name messaging-service
This post is licensed under CC BY 4.0 by the author.