分类
kubernetes

kubectl 操作记录

设置 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

查看 contexts clusters

kubectl config get-contexts
kubectl config get-clusters

删除 context cluster

kubectl --kubeconfig=./KUBECONFIG_of_my config delete-context gke_europe-west2_123
kubectl --kubeconfig=./KUBECONFIG_of_my config delete-cluster gke_europe-west2_123

发表评论

电子邮件地址不会被公开。 必填项已用*标注