alias k=kubectl
complete -F __start_kubectl k
source <(kubectl completion bash)
echo "source <(kubectl completion bash) >> ~/.bashrc
kubectl config set-context $(kubectl config current-context) --namespace=configmaps
kubectl get events --sort-by=".metadata.managedFields[0].time"
kubectl get pods -o=jsonpath="{.items[*]['metadata.name', 'metadata.namespace']}".`
kubectl get pods -l <lable> -o jsonpath={.items[*].spec.containers[*].name}`
¶ Kubectl Commands
kubectl get pods --all-namespaces
¶ Create pod and log into it.
kubectl run --generator=run-pod/v1 <pod name> --rm -it --image=<image location/name> -- <command>
kubectl get secret <secret> -o jsonpath="{.data.password}"| base64 --decode && echo
kubectl api-resources|more
kubectl get pods --all-namespaces
kubectl get pod <pod name> -o yaml --export
¶ create yml file based on kubectl run command w/out creating
kubectl run nginx --image=nginx --port=80 --replicas=2 --expose --dry-run -o yaml> 2-deployment.yaml
kubectl get pods --all-namespaces -L k8s-app <comma sep list of labels>
kubectl get pods --all-namespaces -l k8s-app=kube-proxy --show-labels
kubectl get pods -n kube-system kube-roxy-hwjjl --output-yaml
kubectl get pods --all-namespaces -o wide --show-labels
kubectl show all
kubectl show deployments
kubectl describe pod <pod name>
kubectl describe quota
Name: default
Namespace: 104387-ida
Resource Used Hard
-------- ---- ----
limits.cpu 0 16
limits.memory 0 40Gi
requests.cpu 0 8
requests.memory 0 20Gi
Limits = Namespace Limits
requests = pod limits.
¶ Create a container and log into it
kubectl run --generator=run-pod/v1 <pod name> --rm -it --image=<image location/name> -- <command>
kubectl run --generator=run-pod/v1 tomcat-85-rpm --rm -it --image=busybox -- /bin/bash
# You will then be able to reattach with:
kubectl attach $pod-name -c $pod-container -i -t after you exit the shell.
#Get available pods
kubectl get pods
#You will need to know the container name from the yml file if there are multiple containers in the pod
#kubectl exec <pod> -c <container> -it "/bin/bash"
kubectl exec apex-gold-deployment-7788dd5b4c-h2gz6 -c tomcat -it "/bin/bash"