

























AhmetB started an excellent thread yesterday where he asked people to share a Kubernetes CLI (kubectl) tip that they think a lot of users don't know about.
There are so many excellent tips I decided to collect the most interesting ones in a single post. The first thing that I typically do when I am on a new machine is to set the alias for kubectl:
If you're working with Kubernetes, you'll be typing kubectl a lot, so why not make it shorter.
Enjoy the tips below and let us know if you have any other tips you want to share. Here are all the tips in no particular order.
kubectl autoscale deployment foo --min=2 --max=10
kubectl create job --from=cronjob/<name of cronjob> <name of this run>
kubectl -n <namespace> auth can-i --list --as system:serviceaccount:<namespace>:<service account name>
# To add annotation
kubectl annotate <resource-type>/<resource-name> foo=bar
# To remove annotation
kubectl annotate <resource-type>/<resource-name> foo-
kubectl get events --sort-by=".lastTimestamp"
kubectl get events -w --field-selector=type=Warning -A
EVENT column to the list of watched podskubectl get pods --watch --output-watch-events
kubectl get --raw /apis/apps/v1
# Get metrics
kubectl get --raw /metrics
kubectl wait --for=condition=ready pod -l foo=bar
kubectl get deployments,replicasets,pods,services --selector=hello=yourecute
kubectl port-forward svc/<service-name> <local-port>:<remote-port>
kubectl set env <resource>/<resource-name> --list
kubectl get po -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name
kubectl create deploy nginx-deployment --image=nginx --dry-run=client -o yaml
kubectl top pods -A --sort-by='memory'
kubectl get pods -l 'app in (foo,bar)'
kubectl logs <pod-name> --previous
kubectl cp <namespace>/<pod>:<file_path> <local_file_path>
kubectl delete pod <pod-name> --now
kubectl get <resource> -o wide
# Edit a resource and get the patch
kubectl edit <resource>/<name> --output-patch
# Use the output from the command above to apply the patch
kubectl patch --patch=<output_from_previous_command>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。