It's the hottest tool on the market. You wish you knew it as well as the other guy.
kubectl exec -n <namespace> -it <pod_name> -- /bin/bash
kubectl port-forward --namespace <namespace> <pod_name> <local_port>:<pod_port>
Then in your browser run localhost:<local_port># Use this to identify json path to pod name
kubectl get pod --namespace <namespace> -l <label_key>=<label value> --output json
# Should output just the pod name
kubectl get pod --namespace <namespace> -l <label_key>=<label value> --output jsonpath='{.items[0].metadata.name}'
# Outputs metadata of secret
> kubectl -n <namespace> describe secrets/<secret_name>
Name: <secret_name>
Namespace: <namespace>
Labels: app.kubernetes.io/name=<namespace>
environment=prod
Annotations: <none>
Type: Opaque
Data
====
host: 32 bytes
password: 32 bytes
port: 4 bytes
username: 32 bytes
default_user.conf: 96 bytes
You can then get those secrets using the data above. Example.kubectl -n <namespace> get secrets/<secret_name> --template={{.data.username}} | base64 -D
kubectl -n <namespace> get secrets/<secret_name> --template={{.data.password}} | base64 -D
Kustomize is a tool to abstract your k8s yamls and dynamically create new types of environments. Kustomize is now automatically included part of kubernetes. It seems like this is their supported system going forward.
Get a diff of your changes to prod.
kustomize build prod | kubectl diff -f -
Linting - Syntax Fixes and Update
cd <path to kustomize.yaml dir>
kustomize edit fix
k9s in your terminal..bashrckubessh() {
/usr/bin/kubectl -n ${1} exec -it ${2} /bin/bash
}
kubelogs() {
/usr/bin/kubectl -n ${1} logs -f ${2}
}
kubepods() {
/usr/bin/kubectl get pods -n ${1} |grep -E Running\|STATUS
}
kubedeps() {
/usr/bin/kubectl -n ${1} get deploy
}
kubekick() {
/usr/bin/kubectl -n ${1} set env deployment/${2} RESTARTED="$(date +%s)"
}
kubestop() {
/usr/bin/kubectl -n ${1} scale --replicas=0 deployment/${2}
}
kubestart() {
/usr/bin/kubectl -n ${1} scale --replicas=1 deployment/${2}
}