kubectl命令大全
Kubectl是一个命令行接口,用于运行针对Kubernetes集群的操作。以下是一些常用的kubectl命令:
1、获取资源:
# 查看集群节点信息
kubectl get nodes -o wide
# 查看集群组件健康状态
kubectl get cs
# 查看pods
kubectl get pods -A -o wide
# 指定命名空间查看pods
kubectl get pods -n namespaces
# 查看服务
kubectl get svc -A -o wide
2、创建或更新资源:
kubectl create -f ./my-deployment.yaml
kubectl apply -f ./my-deployment.yaml
2、删除资源:
kubectl delete pods my-pod
kubectl delete svc my-service
4、描述资源:
kubectl describe nodes my-node
kubectl describe pods my-pod
5、日志和跟踪:
kubectl logs my-pod
kubectl logs my-pod -f
kubectl exec -it my-pod -- /bin/bash
6、标签和选择器:
kubectl label nodes my-node disktype=ssd
kubectl get pods -l disktype=ssd
7、配置文件和对象:
kubectl create -f ./my-service.yaml
kubectl get service my-service -o yaml
8、更新资源:
kubectl scale --replicas=3 rs/my-replica-set
kubectl autoscale deployment my-deployment --min=2 --max=10
9、更新Kubernetes集群:
kubectl apply -f https://example.com/my-deployment.yaml
10、使用kubectl插件:
kubectl plugin example-plugin
11、更新kubectl到最新版本:
sudo kubectl update
12、获取可用的上下文:
kubectl config get-contexts
13、切换上下文:
kubectl config use-context my-cluster-name
14、获取所有命令和参数的完整列表:
kubectl options
15、获取特定命令的帮助:
kubectl get --help