k8s 安装部署 (无坑)!!!!!
作者:互联网
k8s简介:
k8s全称kubernetes,k8s是一个完备的分布式系统,具备集群管理,自我修复、滚动升级和在线扩容能力。同时还提供了完善的管理工具,包含了开发,测试,运维各个环节。
规划:
ip | Hostname |
---|---|
192.168.100.203 | k8s-master |
192.168.100.204 | k8s-node1 |
192.168.100.205 | k8s-node2 |
所需软件包:
docker-k8s.tar
k8s-master.zip
k8s-node.tar
安装部署:
docker安装:(三台机器全部需要安装)
解压后会出现pkg目录,查看pkg目录下的安装是否正常
k8s-master:
tar -xf docker-k8s.tar
安装pkg目录下的所有软件包:yum localinstall *.rpm
k8s-node1:
tar -xf k8s-node.tar
安装pkg目录下的所有软件包:yum localinstall *.rpm
k8s-node2:
tar -xf k8s-node.tar
安装pkg目录下的所有软件包:yum localinstall *.rpm
到这里 三台服务器docker 安装完成!!!
master安装;
k8s-master安装:(只在master节点安装)
进入到解压目录
/opt/packages/k8s-master
unzip k8s-master.zip
安装软件包:
yum localinstall -y *.rpm
node节点安装:
拷贝安装到packages目录下
ansible node -m copy -a “src=/data/packages/k8s/k8s-node.tar dest=/opt/packages”
k8s-node1:
mkdir node
tar -xf k8s-node.tar -C node
yum install -y *.rpm
k8s-node2:
mkdir node
tar -xf k8s-node.tar -C node
yum install -y *.rpm
到此node节点和master已安装完成!!!
配置etcd节点:
vim /etc/etcd/etcd.conf
修改以下两行:
** 6 ETCD_LISTEN_CLIENT_URLS=“http://0.0.0.0:2379” ----监听地址**
21 ETCD_ADVERTISE_CLIENT_URLS=“http://192.168.100.203:2379” ----客户端连接地址,本地ip地址
重启服务并计入开机自启:
systemctl restart etcd
systemctl enable etcd
测试:
etcd配置成功!!!
配置master节点
apiserver配置:
vim /etc/kubernetes/apiserver
KUBE_API_ADDRESS="–insecure-bind-address=0.0.0.0" —监听地址
KUBE_API_PORT="–port=8080" —api端口
KUBELET_PORT="–kubelet-port=10250" —kublete端口
KUBE_ETCD_SERVERS="–etcd-servers=http://192.168.100.203:2379" —etcd地址
KUBE_SERVICE_ADDRESSES="–service-cluster-ip-range=10.254.0.0/16" —service地址范围。组件
control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" —去掉ServiceAccount,认证相关,因为我们无法获取认证,所以去掉
启动核心组件:
systemctl enable kube-apiserver
systemctl start kube-apiserver
systemctl enable kube-controller-manager
systemctl start kube-controller-manager
systemctl enable kube-scheduler
systemctl start kube-scheduler
node节点配置:
k8s-node1和k8s-node2全部操作:
vim /etc/kubernetes/config
KUBE_MASTER="–master=http://192.168.100.203:8080"
kubelet配置(node节点)
vim /etc/kubernetes/kubelet
KUBELET_ADDRESS="–address=0.0.0.0" -----监听地址
KUBELET_PORT="–port=10250" -----kublete端口
KUBELET_HOSTNAME="–hostname-override=192.168.100.205" -----hostname本机ip地址即可
KUBELET_API_SERVER="–api-servers=http://192.168.100.203:8080" -----apiserver地址
KUBELET_POD_INFRA_CONTAINER="–pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
启动服务:
systemctl enable kubelet
systemctl start kubelet
systemctl enable kube-proxy
systemctl start kube-proxy
到此安装完成,验证节点状态:
master上执行:
kubectl get nodes
所有节点都已存在!!!
网络配置,所有节点(flannel):
ansible k8s -m yum -a “name=flannel state=installed”
修改配置文件:
k8s-master
sed -i ‘s#127.0.0.1:2379#192.168.100.203:2379#g’ /etc/sysconfig/flanneld
k8s-node1
sed -i ‘s#127.0.0.1:2379#192.168.100.203:2379#g’ /etc/sysconfig/flanneld
k8s-node2
sed -i ‘s#127.0.0.1:2379#192.168.100.203:2379#g’ /etc/sysconfig/flanneld
master 创建网络并验证:
etcdctl mk /atomic.io/network/config ‘{ “Network”: “172.16.0.0/16”}’
etcdctl get /atomic.io/network/config
成功!!!
master重启服务:
[root@k8s-master ~]# systemctl restart kube-apiserver
[root@k8s-master ~]# systemctl restart docker
[root@k8s-master ~]# systemctl restart kube-controller-manager
[root@k8s-master ~]# systemctl restart kube-scheduler
[root@k8s-master ~]# systemctl start flanneld
[root@k8s-master ~]# systemctl eanble flanneld
node节点重启服务:
ansible node -m service -a ‘name=flanneld state=started’
ansible node -m service -a ‘name=flanneld enabled=yes’
ansible node -m service -a ‘name=docker state=restarted’
ansible node -m service -a ‘name=kubelet state=restarted’
查看网卡:ifconfig -a
配置镜像仓库:
master节点
修改docker 配置文件:
vim /etc/sysconfig/docker
–registry-mirror=https://换成你自己的阿里云加速地址或者docker’官方地址 --insecure-registry=192.168.100.203:5000
重启docker
systemctl restart docker
创建本地仓库:
[root@k8s-master ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
测试:
[root@k8s-master ~]# docker pull nginx
docker tag nginx 192.168.100.203/test/nginx:v1
上传镜像:
[root@k8s-master ~]# docker push 192.168.100.203:5000/test/nginx:v1
node节点:
node1
[root@k8s-node1 node]# vim /etc/sysconfig/docker
–insecure-registry=192.168.100.203:5000
node2
[root@k8s-node2 /]# vim /etc/sysconfig/docker
–insecure-registry=192.168.100.203:5000
测试仓库:
docker pull 192.168.100.203:5000/test/nginx:v1
本地镜像仓库完成!!!
到此k8s 基础环境搭建完成!!!
第一次写文章,有很多不足的地方,请各位大神指导!!谢谢
标签:node,部署,192.168,systemctl,master,无坑,docker,k8s 来源: https://blog.csdn.net/strivelcy/article/details/106619412