8

我今天重新启动了系统。之后,我的主系统和 Web 浏览器未连接以查找 kubernetes GUI。

当我运行命令systemctl status kube-apiserver.service时,它会给出如下所示的输出:

kube-apiserver.service
  Loaded: not-found (Reason: No such file or directory)
  Active: inactive (dead)

怎么可能api-server重启?

4

4 回答 4

6

您是否直接下载并安装了Kubernetes 控制器二进制文件

1)如果是,检查kube-apiserver.servicesystemd单元文件是否存在:

cat /etc/systemd/system/kube-apiserver.service

2)如果没有,您可能使用 kubeadm 安装了
通过此设置,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  ..

而不是作为系统服务。

因此,由于您无法在 K8S 中重新启动 pod,因此您必须将其删除:

kubectl delete pod/kube-apiserver-master-k8s -n kube-system

并且会立即创建一个新的 pod。


(*) 当您运行kubeadm init时,您应该会看到为控制平面静态 Pods创建清单:

.
. 
[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"
.
.

对应的yamls:

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
    .
    .
    .
于 2020-10-13T22:26:26.820 回答
1

我有类似的问题,但做了一些简单的事情来解决这个问题。我认为它只是systemctl status kube-apiserver

如果上述工作,请尝试这些步骤

在大师:

重启所有服务 etcd kube-apiserver kube-controller-manager kube-scheduler flanneld

在工人/节点上:

重启所有服务 kube-proxy kubelet flanneld docker

例如:

systemctl restart kube-controller-manager
systemctl enable kube-controller-manager
systemctl status kube-controller-manager

注意:如果它的节点既是master又是worker。在同一个节点上启动。

上述步骤对我有用(但我们正在开发 1.7)。希望有帮助

于 2018-08-09T09:15:10.977 回答
1

将 kube-apiserver 清单文件从 /etc/kubernetes/manifests 文件夹移动到临时文件夹。这种方法的优点是 - 只要文件从清单文件夹中删除,您就可以停止 kube-apiserver。

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
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:~$ 
于 2021-05-21T00:05:32.807 回答
0

您可以使用以下命令重新启动 api-server:

systemctl restart kube-apiserver.service

但是,如果您不想通过 SSH 连接到控制器节点,请运行以下命令:

kubectl -n kube-system delete pod -l 'component=kube-apiserver'
于 2020-08-09T14:53:57.340 回答