在linux中离线安装k8s的master, 包括kube-apiserver, kube-controller-manager, kube-scheduler

Posted muzizongheng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在linux中离线安装k8s的master, 包括kube-apiserver, kube-controller-manager, kube-scheduler相关的知识,希望对你有一定的参考价值。

目录

1.首先建立3个centos7.6的虚拟机。比如用流行的VirtualBox

2.从k8s的github上下载最新版本的安装包。https://github.com/kubernetes/kubernetes/releases

3.通过winscp把windows上的下载的安装包copy到centos虚拟机上

4.更改各虚拟机的hostname, 比如一个为k8s-master:hostnamectl set-hostname k8s-master

5.先安装etcd服务, 参考前面的例子。 假设etcd和kube-apiserver的ip都是:10.6.119.106

6.在同一台机器上开始安装kube-apiserver

7.利用tar -xvzf命令解压后, 把kube-apiserver复制到/usr/local/bin/下。  如:mv /root/Downloads/kubernetes/server/bin/kube-apiserver /usr/local/bin/kube-apiserver

8.在/usr/lib/systemd/system目录下创建kube-apiserver.service,内容如下:

9.在/etc/下创建/etc/kube-apiserver/, 然后创建配置/etc/kube-apiserver/kube-apiserver.conf文件

10. 在/var/lib/下新建目录kube-apiserver

11.配置kube-apiserver开机启动

12. 发现enable报错:Failed to execute operation: Bad message。 查看/var/log/message发现具体内容为:

13.重复7-9的步骤, 配置kube-controller-manager, kube-scheduler。

14.kube-controller-manager.service如下:

15.  kube-scheduler.service如下:

16.启动

17. sysemctl status xxxx来确认服务是否正确启动

18. kubectl cluster-info  和 kubectl get cs 来查看下 master是否正常


 

1.首先建立3个centos7.6的虚拟机。比如用流行的VirtualBox

2.从k8s的github上下载最新版本的安装包。https://github.com/kubernetes/kubernetes/releases

3.通过winscp把windows上的下载的安装包copy到centos虚拟机上

4.更改各虚拟机的hostname, 比如一个为k8s-master:hostnamectl set-hostname k8s-master

5.先安装etcd服务, 参考前面的例子。 假设etcd和kube-apiserver的ip都是:10.6.119.106

6.在同一台机器上开始安装kube-apiserver

7.利用tar -xvzf命令解压后, 把kube-apiserver复制到/usr/local/bin/下。  如:mv /root/Downloads/kubernetes/server/bin/kube-apiserver /usr/local/bin/kube-apiserver

8.在/usr/lib/systemd/system目录下创建kube-apiserver.service,内容如下:

[Unit]

Description=Kubernetes API Service

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=network.target

After=etcd.service

[Service]

WorkingDirectory=/var/lib/kube-apiserver/

EnvironmentFile=-/etc/kube-apiserver/kube-apiserver.conf

ExecStart=/usr/local/bin/kube-apiserver $KUBE_LOGTOSTDERR  $KUBE_LOG_LEVEL $KUBE_ETCD_SERVERS $KUBE_API_ADDRESS $KUBE_API_PORT   $KUBELET_PORT $KUBE_ALLOW_PRIV $KUBE_SERVICE_ADDRESSES  $KUBE_ADMISSION_CONTROL $KUBE_API_ARGS

Restart=on-failure

Type=notify

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

 

 

9.在/etc/下创建/etc/kube-apiserver/, 然后创建配置/etc/kube-apiserver/kube-apiserver.conf文件

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

KUBE_API_PORT="--insecure-port=8080"

KUBE_ETCD_SERVERS="--etcd-servers=http://10.6.119.106:2379"

KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=169.169.0.0/16"

KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"

KUBE_API_LOG="--logtostderr=false --log-dir=/var/lib/kube-apiserver  --v=2"

KUBE_API_ARGS=" "

 

10. 在/var/lib/下新建目录kube-apiserver

 

11.配置kube-apiserver开机启动

systemctl daemon-reload

systemctl enable kube-apiserver.service

systemctl start kube-apiserver.service

 

12. 发现enable报错:Failed to execute operation: Bad message。 查看/var/log/message发现具体内容为:

Mar 18 20:01:22 RT-NODE1 systemd:  [/usr/lib/systemd/system/kube-apiserver.service:9] Trailing garbage,  ignoring.

Mar 18 20:01:22 RT-NODE1 systemd:  [/usr/lib/systemd/system/kube-apiserver.service:10] Missing '='.

 

也就是kube-apiserver.service内容的ExecStart配置有问题,对比了网上其他的配置以及替换测试发现还是同样的错。 后来把execstart的多参数放在一行启动成功了。

如下:ExecStart=/usr/local/bin/kube-apiserver $KUBE_LOGTOSTDERR  $KUBE_LOG_LEVEL $KUBE_ETCD_SERVERS $KUBE_API_ADDRESS $KUBE_API_PORT   $KUBELET_PORT $KUBE_ALLOW_PRIV $KUBE_SERVICE_ADDRESSES  $KUBE_ADMISSION_CONTROL $KUBE_API_ARGS

 

13.重复7-9的步骤, 配置kube-controller-manager, kube-scheduler。

 

14.kube-controller-manager.service如下:

[Unit]

Description=Kubernetes Controller Manager

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=kube-apiserver.service

Requires=kube-apiserver.service

[Service]

WorkingDirectory=/var/lib/kube-apiserver/

EnvironmentFile=-/etc/kube-apiserver/kube-controller-manager.conf

ExecStart=/usr/local/bin/kube-controller-manager  $KUBE_CONTROLLER_MANAGER_ARGS

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

 

kube-controller-manager.conf如下:

KUBE_CONTROLLER_MANAGER_ARGS="--master=http://10.6.119.106:8080  --logtostderr=true --log-dir=/var/lib/kube-apiserver/ --v=0"

 

15.  kube-scheduler.service如下:

[Unit]

Description=Kubernetes Scheduler Plugin

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=kube-apiserver.service

Requires=kube-apiserver.service

[Service]

EnvironmentFile=-/etc/kube-apiserver/kube-scheduler.conf

ExecStart=/usr/local/bin/kube-scheduler $KUBE_SCHEDULER_ARGS

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

 

kube-scheduler.conf如下:

KUBE_SCHEDULER_ARGS="--master=http://10.6.119.106:8080 --logtostderr=true  --log-dir=/var/lib/kube-apiserver --v=0"

 

16.启动

systemctl daemon-reload

systemctl enable kube-controller-manager.service

systemctl start kube-controller-manager.service

systemctl enable kube-scheduler.service

systemctl start kube-scheduler.service

 

17. sysemctl status xxxx来确认服务是否正确启动

 

18. kubectl cluster-info  和 kubectl get cs 来查看下 master是否正常

[root@k8s-master ~]#    kubectl cluster-info

Kubernetes master is running at http://localhost:8080

 

 

 

[root@k8s-master ~]# kubectl get cs

NAME                 STATUS    MESSAGE             ERROR

controller-manager   Healthy   ok

scheduler            Healthy   ok

etcd-0               Healthy   "health":"true"

 

 

调试和离线文件参考:https://blog.csdn.net/muzizongheng/article/details/105067876

以上是关于在linux中离线安装k8s的master, 包括kube-apiserver, kube-controller-manager, kube-scheduler的主要内容,如果未能解决你的问题,请参考以下文章

如何在 linux 中离线安装 dlib?

如何在 linux 中离线安装 vscode-server [重复]

centos中离线安装docker 和docker compose

centos中离线安装docker 和docker compose

在centos7中离线方式安装mysql5.7

在 anaconda 中离线安装 cv2 模块