今天我重新启动了系统。之后我的主系统和网络浏览器无法连接以查找Kubernetes GUI。
当我运行命令systemctl status kube-apiserver.service
时,它的输出如下:
kube-apiserver.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
如何重新启动 api-server
?
今天我重新启动了系统。之后我的主系统和网络浏览器无法连接以查找Kubernetes GUI。
当我运行命令systemctl status kube-apiserver.service
时,它的输出如下:
kube-apiserver.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
如何重新启动 api-server
?
你是否直接下载并安装了Kubernetes 控制器二进制文件?
1) 如果是这样,请检查是否存在kube-apiserver.service
systemd单元文件:
cat /etc/systemd/system/kube-apiserver.service
2) 如果不是这种情况,你很可能是使用kubeadm安装了K8S。
在这种设置下,kubeapi-server正在主节点上作为一个pod运行:
kubectl get pods -n kube-system
NAME READY STATUS
coredns-f9fd979d6-jsn6w 1/1 Running ..
coredns-f9fd979d6-tv5j6 1/1 Running ..
etcd-master-k8s 1/1 Running ..
kube-apiserver-master-k8s 1/1 Running .. #<--- Here
kube-controller-manager-master-k8s 1/1 Running ..
kube-proxy-5kzbc 1/1 Running ..
kube-scheduler-master-k8s 1/1 Running ..
而不是作为systemd服务。
所以,在K8S中你无法重新启动pod,你只能删除它:
kubectl delete pod/kube-apiserver-master-k8s -n kube-system
并且会立即创建一个新的Pod。
(*) 当您运行kubeadm init时,您应该看到控制平面静态Pod的清单创建:
.
.
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
.
.
对应的yaml文件:
ubuntu@master-k8s:/etc/kubernetes/manifests$ ls -la
total 24
drwxr-xr-x 2 root root 4096 Oct 14 00:13 .
drwxr-xr-x 4 root root 4096 Sep 29 02:30 ..
-rw------- 1 root root 2099 Sep 29 02:30 etcd.yaml
-rw------- 1 root root 3863 Oct 14 00:13 kube-apiserver.yaml <----- Here
-rw------- 1 root root 3496 Sep 29 02:30 kube-controller-manager.yaml
-rw------- 1 root root 1384 Sep 29 02:30 kube-scheduler.yaml
而且 kube-apiserver 规范:
apiVersion: v1
kind: Pod
metadata:
annotations:
kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 10.100.102.5:6443
creationTimestamp: null
labels:
component: kube-apiserver
tier: control-plane
name: kube-apiserver
namespace: kube-system
spec:
containers:
- command:
- kube-apiserver
- --advertise-address=10.100.102.5
- --allow-privileged=true
- --authorization-mode=Node,RBAC
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --enable-admission-plugins=NodeRestriction
- --enable-bootstrap-token-auth=true
.
.
.
kubectl delete pod/kube-apiserver-master-k8s -n kube-system
来重启 kube-apiserver 容器。这将删除 pod。容器将继续运行。Pod 将立即重新创建,这是正确的,并将正在运行的容器重新分配给 Pod 而不会杀死容器进程!
编辑:如果您想重启 kube-apiserver,则必须杀死容器本身。例如通过 docker 或 crictl。 - Nortolcrictl stop
直接杀死容器,它起作用了。 - ryanbrainardvagrant@master01:~$ ll /etc/kubernetes/manifests/
total 16
-rw------- 1 root root 3315 May 12 23:24 kube-controller-manager.yaml
-rw------- 1 root root 1384 May 12 23:24 kube-scheduler.yaml
-rw------- 1 root root 2157 May 12 23:24 etcd.yaml
-rw------- 1 root root 3792 May 20 00:08 kube-apiserver.yaml
vagrant@master01:~$ sudo mv /etc/kubernetes/manifests/kube-apiserver.yaml /tmp/
vagrant@master01:~$
vagrant@master01:~$ ll /etc/kubernetes/manifests/
total 12
-rw------- 1 root root 3315 May 12 23:24 kube-controller-manager.yaml
-rw------- 1 root root 1384 May 12 23:24 kube-scheduler.yaml
-rw------- 1 root root 2157 May 12 23:24 etcd.yaml
API服务器现在已经宕机了。
vagrant@master01:~$ k get pods -n kube-system
The connection to the server 10.0.0.2:6443 was refused - did you specify the right host or port?
vagrant@master01:~$
vagrant@master01:~$ sudo mv /tmp/kube-apiserver.yaml /etc/kubernetes/manifests/
vagrant@master01:~$
vagrant@master01:~$ ll /etc/kubernetes/manifests/
total 16
-rw------- 1 root root 3315 May 12 23:24 kube-controller-manager.yaml
-rw------- 1 root root 1384 May 12 23:24 kube-scheduler.yaml
-rw------- 1 root root 2157 May 12 23:24 etcd.yaml
-rw------- 1 root root 3792 May 20 00:08 kube-apiserver.yaml
API服务器现已启动
vagrant@master01:~$ k get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-558bd4d5db-269lt 1/1 Running 5 8d
coredns-558bd4d5db-967d8 1/1 Running 5 8d
etcd-master01 1/1 Running 6 8d
kube-apiserver-master01 0/1 Running 2 24h
kube-controller-manager-master01 1/1 Running 8 8d
kube-proxy-q8mkb 1/1 Running 5 8d
kube-proxy-x6trg 1/1 Running 6 8d
kube-proxy-xxph9 1/1 Running 8 8d
kube-scheduler-master01 1/1 Running 8 8d
weave-net-rh2gb 2/2 Running 18 8d
weave-net-s2cg9 2/2 Running 14 8d
weave-net-wksk2 2/2 Running 11 8d
vagrant@master01:~$
我曾经遇到过类似的问题,但是采取了一些简单的方法来解决。我认为只需要运行systemctl status kube-apiserver
就可以了。
如果上述方法有效,请尝试以下步骤:
在Master节点上:
重启所有服务:etcd、kube-apiserver、kube-controller-manager、kube-scheduler和flanneld。
在Worker/Node节点上:
重启所有服务:kube-proxy、kubelet、flanneld和docker。
E.g:
systemctl restart kube-controller-manager
systemctl enable kube-controller-manager
systemctl status kube-controller-manager
您可以使用以下命令重新启动api服务器:
systemctl restart kube-apiserver.service
然而,如果您不想通过SSH连接到控制节点,请运行以下命令:
kubectl -n kube-system delete pod -l 'component=kube-apiserver'