我是南城余!阿里云開發者平臺專家博士證書獲得者!
歡迎關注我的博客!一同成長!
一名從事運維開發的worker,記錄分享學習。
專注于AI,運維開發,windows?Linux?系統領域的分享!
知識庫鏈接:
K8s命令合集 · 語雀
在Kubernetes中,通常使用kubectl命令行工具來與集群進行交互。以下是一些常用的kubectl命令,用于管理和操作Kubernetes集群中的資源:
- 基本操作:
-
kubectl get <resource>
:獲取資源的列表。kubectl describe <resource> <name>
:顯示資源的詳細信息。kubectl create -f <file>
:從文件創建資源。kubectl apply -f <file>
:應用配置文件來創建或更新資源。kubectl delete <resource> <name>
:刪除資源。
- 查看資源:
-
kubectl get pods
:查看Pods。kubectl get deployments
:查看Deployments。kubectl get services
:查看Services。kubectl get nodes
:查看Nodes。kubectl get namespaces
:查看命名空間。
- 管理資源:
-
kubectl create deployment <name> --image=<image>
:創建一個Deployment。kubectl expose deployment <name> --port=<port>
:暴露Deployment為Service。kubectl scale deployment <name> --replicas=<replica_count>
:擴展Deployment的副本數量。kubectl apply -f <file>
:應用配置文件。
- 日志和調試:
-
kubectl logs <pod_name>
:查看Pod的日志。kubectl exec -it <pod_name> -- /bin/bash
:在Pod中執行交互式shell。kubectl describe pod <pod_name>
:查看Pod的詳細信息。
- 故障排除:
-
kubectl get events
:查看集群事件。kubectl describe node <node_name>
:查看節點的詳細信息。kubectl describe pod <pod_name>
:查看Pod的詳細信息。
- 其他操作:
-
kubectl proxy
:創建一個代理,允許訪問集群內部服務。kubectl apply -f <file>
:應用配置文件。kubectl rollout status deployment/<deployment_name>
:查看Deployment的滾動更新狀態。
這些是一些常用的kubectl命令,您可以根據需要進一步了解和探索其他命令以管理和操作Kubernetes集群中的資源