设置 master
kubectl label node node-master.foo.bar kubernetes.io/role=master node "node-master.foo.bar" labeled
查看集群组件信息
kubectl get cs
查看集群的 master api 地址
kubectl cluster-info kubectl cluster-info dump
查看集群的各种资源类型
kubectl api-resources | grep istio
kubectl get pods --namespace=kube-system
强制删除 pod
kubectl delete pod nginx-1849696770-2pk8t -n myspace --grace-period=0 --force
转发一个端口
kubectl -n monitoring port-forward deployment/getup-grafana 3000:3000 kubectl -n monitoring port-forward alertmanager-getup-prometheus-operator-alertmanager-0 9093:9093 kubectl -n monitoring port-forward prometheus-getup-prometheus-operator-prometheus-0 9090:9090
exec 执行长命令被截断,需要用 —
kubectl exec $POD_NAME tail -n 10 /var/log/newrelic_agent.log Error from server (NotFound): namespaces "10" not found 应该用 kubectl exec $POD_NAME -- tail -n 10 /var/log/newrelic_agent.log 或 kubectl exec $POD_NAME -- bash -c "tail -n 10 /var/log/newrelic_agent.log"
查看所有事件
kubectl get events
kubectl -n istio-system port-forward prometheus-6cabcdab97-mwptl 18080:9090 kubectl -n istio-system port-forward grafana-fabcd765b-vtcxp 18080:3000 kubectl -n istio-system port-forward kiali-8babb947c-b5g5m 18080:20001
kubectl api-resources
app=account_service kubectl logs --tail 10 -f -l app=$app -n default -c $app
kubectl get secret config1 -o json | jq '.data | map_values(@base64d)'
kubectl get all -n jenkins NAME READY STATUS RESTARTS AGE pod/jenkins-8d6cc58f-dnfv6 1/1 Running 0 3d5h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/jenkins ClusterIP 10.31.30.980/TCP 544d service/jenkins-agent LoadBalancer 10.31.25.64 172.170.0.41 50000:21700/TCP 544d service/jenkins-agent-public LoadBalancer 10.31.25.94 xx.xx.xx.xxx 50000:22289/TCP 402d NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/jenkins 1/1 1 1 544d NAME DESIRED CURRENT READY AGE replicaset.apps/jenkins-7f57bfbd76 0 0 0 544d replicaset.apps/jenkins-8d6cc58f 1 1 1 367d
查看 pod 的名字
for pod in `kubectl get pods -n dev -o jsonpath={.items..metadata.name} `; do kubectl get pod $pod -n dev ; done
查看 svc 的 ip
kubectx | grep gke_ | while read line; do echo $line; kubectl --context $line get svc istio-ingressgateway -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}'; echo; done
查看 image 和 containerID
kubectl get pods -n dev -o jsonpath='{range .items[*].status.containerStatuses[*]}{.image}{"\n"}{.containerID}{"\n\n"}{end}'
用 go template
kubectl get nodes -l cloud.google.com/machine-family=n1 -o go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'
Leave a Reply