如何重新启动kube-apiserver?

时间:2018-08-03 06:28:03

标签: kubernetes

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

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

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

有人可以建议我如何克服这个问题。

4 个答案:

答案 0 :(得分:2)

您可以使用以下方法重新启动api服务器:

systemctl restart kube-apiserver.service

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

kubectl -n kube-system delete pod -l 'component=kube-apiserver'

答案 1 :(得分:1)

您是否直接下载并安装了Kubernetes Controller Binaries

1)如果是,请检查kube-apiserver.service系统单位文件是否存在:

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

2)否则,您可能已将K8S与一起安装。
通过此设置, kubeapi服务器在主节点上作为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时,应该看到控制平面static 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
    .
    .
    .

答案 2 :(得分:0)

我有类似的问题,但是做了一些简单的事情来解决这个问题。我认为它只是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上工作)。希望有帮助

答案 3 :(得分:0)

将 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:~$