centos7.8离线二进制安装K8s
这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入欢迎使用Mar
centos7.8二进制安装k8s
二进制安装k8s
下载链接:
etcd下载链接:https://github.com/etcd-io/etcd/releases
k8s组件下载:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md#downloads-for-v1188
环境:centos7.8 x86_64
内核版本:3.10.0-1127.el7.x86_64
kubernets版本:v1.18.8
docker版本:18.0.9CE
环境架构:
k8s-master01| 192.168.54.161
k8s-work01 | 192.168.54.162
k8s-work02 | 192.168.54.163
第一阶段:
配置master节点:
第一步:etcd安装
[root@k8s-master01 ~]# cat /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd
[Install]
WantedBy=multi-user.target
touch /etc/etcd/etcd.conf
mkdir /var/lib/etcd/
systemctl daemon-reload
systemctl start etcd.service
systemctl status etcd.service
验证etcd是否正确启动:etcdctl endpoint health
问题:
如果有如下报错,检查WorkingDirectory、EnvironmentFile、ExecStart配置目录是否存在,没有则手动创建:
二、安装kube-apiserver服务
cd kubernetes/server/bin
cp kube-apiserver kube-controller-manager kube-scheduler /usr/local/bin/
[root@k8s-master01 ~]# cat /usr/lib/systemd/system/kube-apiserver.service
[Unit]
Description=kubernetes API Server
Documentation=https://github.com/GoogoleCloudPlatform/kubernetes
After=etcd.service
Wants=etcd.service
[Service]
EnvironmentFile=/etc/kubernetes/apiserver
ExecStart=/usr/local/bin/kube-apiserver $KUBE_API_ARGS
Restart=on-failure
Type=notify
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
[root@k8s-master01 ~]# cat /etc/kubernetes/apiserver
KUBE_API_ARGS="–etcd-servers=http://127.0.0.1:2379 --insecure-bind-address=0.0.0.0 --insecure-port=8080 --service-cluster-ip-range=169.169.0.0/16 --service-node-port-range=1-65535 --enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota --logtostderr=false --log-dir=/var/log/kubernetes --v=0"
三、安装kube-controller-manager服务
[root@k8s-master01 ~]# cat /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloundPlatform/kubernetes
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
EnvironmentFile=/etc/kubernetes/controller-manager
ExecStart=/usr/local/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
[root@k8s-master01 ~]# cat /etc/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS="–kubeconfig=/etc/kubernetes/kubeconfig --logtostderr=false --log-dir=/var/log/kubernetes --v=0"
[root@k8s-master01 ~]# cat /etc/kubernetes/kubeconfig
apiVersion: v1
kind: Config
users:
- name: client
user:
clusters: - name: default
cluster:
server: http://192.168.54.161:8080
contexts: - context:
cluster: default
user: client
name: default
current-context: default
安装问题:
检查wantedBy是否写错
重启正常
四、安装配置kube-scheduler服务
[root@k8s-master01 ~]# cat /usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GooleCloudPlatform/kubernetes
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
EnvironmentFile=/etc/kubernetes/scheduler
ExecStart=/usr/local/bin/kube-scheduler $KUBE_SCHEDULER_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
[root@k8s-master01 ~]# cat /etc/kubernetes/scheduler
KUBE_SCHEDULER_ARGS="–kubeconfig=/etc/kubernetes/kubeconfig --logtostderr=false --log-dir=/var/log/kubernetes --v=0"
五、启动服务
root@k8s-master01 ~]# systemctl daemon-reload
[root@k8s-master01 ~]# systemctl enable kube-apiserver.service
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl enable kube-controller-manager.service
[root@k8s-master01 ~]# systemctl enable kube-scheduler.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kube-scheduler.service to /usr/lib/systemd/system/kube-scheduler.service.
[root@k8s-master01 ~]# systemctl start kube-scheduler.service
[root@k8s-master01 ~]# systemctl status kube-scheduler.service
服务运行正常,则master上所需服务已全部启动完成
第二阶段:work节点上配置kubelet\kube-proxy服务
一、安装配置kubelet
1、在work节点上面安装配置docker
2、cp kubectl kube-proxy kubelet /usr/local/bin/
mkdir /var/lib/kubelet
[root@k8s-work01 bin]# mkdir /etc/kubernetes
[root@k8s-work01 bin]# vim /etc/kubernetes/kubelet
KUBELET_ARGS="–kubeconfig=/etc/kubernetes/kubeconfig --hostname-override=k8s-work01 --logtostderr=false --log-dir=/var/log/kubernetes --v=0"
mkdir /var/log/kubernetes
vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=/etc/kubernetes/kubelet
ExecStart=/usr/local/bin/kubelet $KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
问题:
kubelet服务启动失败,检查swap是否关闭,相关目录是否创建,去/var/log/kubernetes中查看日志
二、安装配置kube-proxy服务
vim /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
Requires=network.service
[Service]
EnvironmentFile=/etc/kubernetes/proxy
ExecStart=/usr/local/bin/kube-proxy $KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
[root@k8s-work01 ~]# cat /etc/kubernetes/proxy
KUBE_PROXY_ARGS="–kubeconfig=/etc/kubernetes/kubeconfig --logtostderr=false --log-dir=/var/log/kubernetes --v=2"
三、配置kubeconfig文件与master中一致
四、启动服务
systemctl start kubelet.service
systemctl enable kubelet.service
systemctl start kube-proxy.service
systemctl enable kube-proxy.service
测试:
在master节点查看节点,至此k8s已安装完毕,可以创建pod等
更多推荐
所有评论(0)