kubernetes集群常用指令

目录

1.1 基础控制指令

1.2 命令实践

1.3 备注


1.1 基础控制指令
# 查看对应资源: 状态
$ kubectl get  -n  -o wide
​
# 查看对应资源: 事件信息
$ kubectl describe   -n 
​
# 查看pod资源: 日志
$ kubectl logs -f  [CONTINER_NAME] -n 
​
# 创建资源: 根据资源清单
$ kubectl apply[or create] -f .yaml
​
# 删除资源: 根据资源清单
$ kubectl delete -f .yaml
​
# 修改资源: 根据反射出的etcd中的配置内容, 生产中不允许该项操作, 且命令禁止
$ kubectl edit   -n 
1.2 命令实践
# 查看node状态
$ kubectl get node # -o wide 显示更加详细的信息
​
# 查看service对象
$ kubectl get svc
​
# 查看kube-system名称空间内的Pod
$ kubectl get pod -n kube-system
​
# 查看所有名称空间内的pod
$ kubectl get pod -A
​
# 查看集群信息
$ kubectl cluster-info
​
# 查看各组件信息
$ kubectl -s https://api-server:6443 get componentstatuses
​
# 查看各资源对象对应的api版本
$ kubectl explain pod
​
# 查看帮助信息
$ kubectl explain deployment
$ kubectl explain deployment.spec
$ kubectl explain deployment.spec.replicas
1.3 备注
问题一 查看各组件信息,可能会发现错误
$ kubectl -s https://192.168.96.143:6443 get componentstatuses
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS      MESSAGE                                                                                       ERROR
scheduler            Unhealthy   Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused   
controller-manager   Unhealthy   Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused   
etcd-0               Healthy     {"health":"true"}                                                           
​
问题一解决
$ vim /etc/kubernetes/manifests/kube-scheduler.yaml
 10 spec:
 11   containers:
 12   - command:
 13     - kube-scheduler
 14     - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
 15     - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
 16     - --bind-address=127.0.0.1
 17     - --kubeconfig=/etc/kubernetes/scheduler.conf
 18     - --leader-elect=true
 19     - --port=0   # 将此行注释或删除
 
 $ vim /etc/kubernetes/manifests/kube-controller-manager.yaml
  10 spec:
 11   containers:
 12   - command:
 13     - kube-controller-manager
 14     - --allocate-node-cidrs=true
 15     - --authentication-kubeconfig=/etc/kubernetes/controller-manager.conf
 16     - --authorization-kubeconfig=/etc/kubernetes/controller-manager.conf
 17     - --bind-address=127.0.0.1
 18     - --client-ca-file=/etc/kubernetes/pki/ca.crt
 19     - --cluster-cidr=10.244.0.0/16
 20     - --cluster-name=kubernetes
 21     - --cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
 22     - --cluster-signing-key-file=/etc/kubernetes/pki/ca.key
 23     - --controllers=*,bootstrapsigner,tokencleaner
 24     - --kubeconfig=/etc/kubernetes/controller-manager.conf
 25     - --port=0 # 将此行注释或删除
 
$ systemctl restart kubelet
 
$ kubectl -s https://192.168.96.143:6443 get componentstatuses
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok                  
controller-manager   Healthy   ok                  
etcd-0               Healthy   {"health":"true"}

你可能感兴趣的:(kubernetes,容器,云原生)