kubectl常用命令
kubectl cluster-info #查询集群运行信息、版本。
kubectl apply -f test.yaml #部署指定文件,--file
kubectl delete -f test.yaml #取消部署
kubectl run d1 --image httpd:alpine --port 80 #创建d1的Apache镜像
kubectl exec -it redis-master-59694fd4d5-txcbc sh #以sh进入容器
kubectl logs -f redis-master-59694fd4d5-txcbc #查看运行时容器内的log
kubectl get - 类似于 docker ps,查询资源列表
kubectl describe - 类似于 docker inspect,获取资源的详细信息
kubectl logs - 类似于 docker logs,获取容器的日志
kubectl exec - 类似于 docker exec,在容器内执行一个命令
kubectl get pod --output=wide #更多的pod信息
kubectl get pods -A #--all-namespaces所有命名空间下的pod
kubectl describe pods #更详细的pods信息
kubectl get pods -w -l #watch命令,挂起观察
kubectl get events -A --sort-by='.metadata.creationTimestamp' #查询运行时事件倒序
kubectl expose deployment d1 --target-port 80 --type NodePort #将d1暴露为一个svc,指定80端口和NodePort类型。
kubectl scale --replicas=3 deployment/nginx-app #自动扩容到3个,自动加入退出service。
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2 #滚动升级,默认,无中断服务升级
kubectl rolling-update frontend-v1 frontend-v2 --rollback #回滚
kubectl rollout status deployment/nginx-app #查看滚动状态
for i in 0 5; do kubectl exec "web-$i" -- sh -c 'hostname'; done #循环打印web-0到5容器的的hostname
for i in 0 5; do kubectl exec "web-$i" -- sh -c 'echo "$(hostname)" > /usr/share/nginx/html/index.html'; done #写入nginx hostname
标签: linux 命令 k8s kubectl
评论: