kubectl 常用命令

label操作

删除 label version=xx

kubectl label pod webui-746df859ff-z5fwt version-

添加 label
kubectl label pods labelex owner=michael

deploy操作

kubectl create delpoy [deploy_name] --image=nginx

kubectl create deployment httpenv --image=iasonliu/httpenv

kubectl run [pod_name] –image=busybox

example:
kubectl run pingpong --image=alpine ping 1.1.1.1 or kubectl run pingpong2 --image alpine ping 1.1.1.1

当我们使用 kubectl run something启动deplyment的时候,label会是 run=something

kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1

service操作

为webui创建service
kubectl expose deploy/webui --type=NodePort --port=80

log操作

查看deploy日志
kubectl logs deploy/pingpong

查看pod日志
kubect logs [ pod_name]

或者脚本

1
2
3
4
5
6
7
8
9
#!/usr/bin/env bash
DEPLOYMENT=$1

for p in $(kubectl get pods | grep ^${DEPLOYMENT}- | cut -f 1 -d ' '); do
echo ---------------------------
echo $p
echo ---------------------------
kubectl logs $p
done

批量sacle

kubectl get deploy -n <YOUR_NAMESPACE> -o name | xargs -I % kubectl scale % --replicas=0 -n <YOUR_NAMESPACE>


More Ref:

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~