惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
A
About on SuperTechFans
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
博客园 - 【当耐特】
The Cloudflare Blog
F
Fortinet All Blogs
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
罗磊的独立博客
量子位
有赞技术团队
有赞技术团队
V
V2EX
Engineering at Meta
Engineering at Meta

Learn Cloud Native

Plan-based validation for coding agents on Kubernetes | Learn Cloud Native PR validation at scale and a sandbox for every pull request on Kubernetes | Learn Cloud Native 7 practical MCP policies with agentgateway | Learn Cloud Native Agentgateway rate limiting for agents | Learn Cloud Native Local development with coding agents on Kubernetes using Signadot | Learn Cloud Native cuenv: one typed file for your whole project | Learn Cloud Native Preflight: AI Code Review Before You Push Anatomy of AI Agents Accessing Google Drive from Next.js Deploying to Fly.io using Dagger and Github Top Cloud-Native & Kubernetes Certifications [2026 Guide] Rapid microservices development with Signadot How to prepare for Istio certified associate exam (ICA) Global Rate Limiting in Istio with Envoy Rate Limit Service My Journey with Istio: From Incubation to Graduation Cilium Network Policy Tutorial: Secure Kubernetes Step by Step Kubernetes Networking: How kube-proxy and iptables Work Istio ServiceEntry: DNS vs. STATIC Resolution & Endpoints Explained Apply an Istio DestinationRule Globally (Mesh-Wide) Istio Rate Limiting: Configure a Local Rate Limiter in Envoy How to expose custom ports on Istio ingress gateway Portainer Tutorial: A Web UI for Kubernetes & Containers Traefik Proxy 2.x and TLS 101 Setting up SSL certificates with Istio Gateway ArgoCD Best Practices You Should Know 在 OCI Ampere A1 计算实例上运行 AI Running AI On OCI Ampere A1 Instance How to Deploy Traefik Proxy Using Flux and GitOps Principles Firebase Emulators with Next.js: Local Setup Guide Running Hugo on free Ampere VM (Oracle Cloud Infrastructure)
Kubernetes CLI (kubectl) tips you didn't know about
Peter Jausovec · 2022-05-10 · via Learn Cloud Native

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.

1. Set up load-based horizontal pod autoscaling on your Kubernetes resources

kubectl autoscale deployment foo --min=2 --max=10

2. Create a new job from a cronjob

kubectl create job --from=cronjob/<name of cronjob> <name of this run>

3. Enumerate permissions for a given service account

kubectl -n <namespace> auth can-i --list --as system:serviceaccount:<namespace>:<service account name>

4. Annotate resources

# To add annotation
kubectl annotate <resource-type>/<resource-name> foo=bar
# To remove annotation
kubectl annotate <resource-type>/<resource-name> foo-

5. Get a list of endpoints across all namespaces

6. Get a list of events sorted by lastTimestamp

kubectl get events --sort-by=".lastTimestamp"

7. Watch all warnings across the namespaces

kubectl get events -w --field-selector=type=Warning -A

8. Add the EVENT column to the list of watched pods

kubectl get pods --watch --output-watch-events

9. Get raw JSON for the various APIs

kubectl get --raw /apis/apps/v1

# Get metrics
kubectl get --raw /metrics

10. Wait for specific pods to be ready

kubectl wait --for=condition=ready pod -l foo=bar

11. Explain the various resources

12. Get all resources that match a selector

kubectl get deployments,replicasets,pods,services --selector=hello=yourecute

13. Forward a port from a service to a local port

kubectl port-forward svc/<service-name> <local-port>:<remote-port>

14. List the environment variables for a resource

kubectl set env <resource>/<resource-name> --list

15. Get a list of pods and the node they run on

kubectl get po -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name

16. Create a starter YAML manifest for deployment (also works for other resources)

kubectl create deploy nginx-deployment --image=nginx --dry-run=client -o yaml

17. Get a list of pods sorted by memory usage

kubectl top pods -A --sort-by='memory'

18. Get a list of pods that have a specific label value set

kubectl get pods -l 'app in (foo,bar)'

19. Get the pod logs before the last restart

kubectl logs <pod-name> --previous

20. Copy a file from a pod to a local file

kubectl cp <namespace>/<pod>:<file_path> <local_file_path>
kubectl delete pod <pod-name> --now

22. Show the logs from pods with specific labels

23. Get more information about the resources (aka wide-view)

kubectl get <resource> -o wide

24. Output and apply the patch

# 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>