Kubernetes/Tools
Jump to navigation
Jump to search
kubectl
- Install
#Latest curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl # Specific version $(VER=v1.13.7; ARCH=amd64; curl -LO https://storage.googleapis.com/kubernetes-release/release/$VER/bin/linux/$ARCH/kubectl) chmod +x ./kubectl; sudo mv ./kubectl /usr/local/bin/kubectl # Verify, kubectl should not be more than -/+ 1 minor version difference then api-server kubectl version --short Client Version: v1.13.7 Server Version: v1.13.7-gke.8 # Autocompletion source <(kubectl completion bash); alias k=kubectl; complete -F __start_kubectl k # Set default namespace kubectl config set-context $(kubectl config current-context) --namespace=dev
Help
$ kubectl --help $ kubectl get --help $ kubectl explain --help $ kubectl explain pod.spec.containers #kubectl knows cluster version, so gives you correct schema details
- kubectl-commands K8s interactive kubectl command reference
Stern
Log tailing and landscape viewing tool. It connects to kubeapi and streams logs from all pods. Thus using this external tool with clusters that have 100ts of containers can be put significant load on kubeapi.
It will re-use kubectl config file to connect to your clusters, so works oob.
Install
# Govendor - this module manager is required export GOPATH=$HOME/go # path where go modules can be found, used by 'go get -u <url>' export PATH=$PATH:$GOPATH/bin # path to the additional 'go' binaries go get -u github.com/kardianos/govendor # there will be no output # Stern (official) mkdir -p $GOPATH/src/github.com/wercker cd $GOPATH/src/github.com/wercker git clone https://github.com/wercker/stern.git && cd stern govendor sync # there will be no output, may take 2 min go install # no output # Stern install by getting binary direct, no need for govendor sudo curl -L https://github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64 -o /usr/local/bin/stern sudo chmod +x /usr/local/bin/stern
Help
$ stern Tail multiple pods and containers from Kubernetes Usage: stern pod-query [flags] Flags: --all-namespaces If present, tail across all namespaces. A specific namespace is ignored even if specified with --namespace. --color string Color output. Can be 'always', 'never', or 'auto' (default "auto") --completion string Outputs stern command-line completion code for the specified shell. Can be 'bash' or 'zsh' -c, --container string Container name when multiple containers in pod (default ".*") --container-state string If present, tail containers with status in running, waiting or terminated. Default to running. (default "running") --context string Kubernetes context to use. Default to current context configured in kubeconfig. -e, --exclude strings Regex of log lines to exclude -E, --exclude-container string Exclude a Container name -h, --help help for stern -i, --include strings Regex of log lines to include --kubeconfig string Path to kubeconfig file to use -n, --namespace string Kubernetes namespace to use. Default to namespace configured in Kubernetes context -o, --output string Specify predefined template. Currently support: [default, raw, json] (default "default") -l, --selector string Selector (label query) to filter on. If present, default to ".*" for the pod-query. -s, --since duration Return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to 48h. --tail int The number of lines from the end of the logs to show. Defaults to -1, showing all logs. (default -1) --template string Template to use for log lines, leave empty to use --output flag -t, --timestamps Print timestamps -v, --version Print the version and exit
- Usage
stern <pod> stern --tail 1 busybox -n <namespace> #this is RegEx that matches busybox1|2|etc
kui terminal
kui is a terminal with visualizations
curl -sL https://raw.githubusercontent.com/IBM/kui/master/tools/install.sh | sh
k9s
Install
curl -O k9s_0.8.2_Linux_x86_64.tar.gz https://github.com/derailed/k9s/releases/download/0.8.2/k9s_0.8.2_Linux_x86_64.tar.gz tar xf k9s_0.8.2_Linux_x86_64.tar.gz --remove-files k9s sudo install k9s /usr/local/bin
References
- kubectl overview - resources types, Namespaced, kinds K8s docs
- kubetail Bash script that enables you to aggregate (tail/follow) logs from multiple pods into one stream. This is the same as running "kubectl logs -f " but for multiple pods.
- kubectx kubens Kubernetes config switches for context and setting up default namespace
- manages different ver kubectl blog
- kubectl Kubectl Conventions
Cheatsheets
- cheatsheet-kubernetes-A4 by dennyzhang