logo资料库

K8S在线安装部署手册.docx

第1页 / 共33页
第2页 / 共33页
第3页 / 共33页
第4页 / 共33页
第5页 / 共33页
第6页 / 共33页
第7页 / 共33页
第8页 / 共33页
资料共33页,剩余部分请下载后查看
1在CentOS7上使用kubeadm搭建k8s-v1.13.5集群
1.1系统初始化
1.1.1设置永久主机名称
1.1.2添加主机名和IP的对应关系
1.1.3m01节点免密码ssh登录其他节点
1.1.4关闭每台机器上的防火墙
1.1.5关闭swap分区
1.1.6设置时区
1.1.7更新系统时间
1.2install docker
1.2.1卸载旧版docker并手动删除/var/lib/docker目录
1.2.2set up docker repository
1.2.3安装docker
1.3installing kubeadm
1.3.1前置要求
1.3.2检查要求的端口
1.3.3关闭SELinux
1.3.4开启CentOS网桥
1.3.5准备k8s的国内yum源
1.3.6安装v1.13.5版本的kubelet kubeadm kubectl
1.3.6.1列出安装过的rpm包
1.3.6.2卸载安装的rpm包
1.3.6.31.3.6.3.安装指定版本的kubeadm
1.3.6.3.11.3.6.3.1.查看可得kubelet版本
1.3.6.3.21.3.6.3.2.查看可得的kubeadm版本
1.3.6.3.31.3.6.3.3.查看可得的kubectl版本
1.3.6.3.41.3.6.3.4.安装1.13.5的kubeadm、kubectl和kubelet(所有节点)
1.3.6.3.51.3.6.3.5.启动kubelet
1.4kubeadm初始化
1.4.1直接尝试执行kubeadm init查看需要拉取的镜像
1.4.2手动拉取谷歌镜像
1.4.3重新打包谷歌镜像
1.4.4再次kubeadm init
1.4.5安装pod网络(只需在master节点执行即可)
1.4.6添加node节点到master节点(slave节点执行)
1.4.7查看节点状态(master)
1.4.8查看pod状态(master)
1.5安装dashboard
1.5.1下载dashboard的yaml文件
1.5.2启动dashboard
1.5.3查看容器和pod日志,在对应的节点上拉取缺失的镜像
1.5.4编辑dashboard服务将type的值由ClusterIP改为NodePort
1.5.5创建用户并绑定权限
1.5.6获得token
1.5.7远程访问
1 在 CentOS7 上 使 用 kubeadm 搭 建 k8s-v1.13.5 集群 1.1 系统初始化 1.1.1设置永久主机名称 hostnamectl set-hostname m01 hostnamectl set-hostname s01 hostnamectl set-hostname s02 1.1.2添加主机名和 IP 的对应关系 cat >> /etc/hosts <
1.1.5关闭 swap 分区 swapoff -a sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab 1.1.6设置时区 # 调整系统 TimeZone timedatectl set-timezone Asia/Shanghai # 将当前的 UTC 时间写入硬件时钟 timedatectl set-local-rtc 0 # 重启依赖于系统时间的服务 systemctl restart rsyslog systemctl restart crond [root@m01 ~]# timedatectl set-timezone Asia/Shanghai [root@m01 ~]# timedatectl set-local-rtc 0 [root@m01 ~]# 1.1.7更新系统时间 ntpdate cn.pool.ntp.org [root@m01 ~]# ntpdate cn.pool.ntp.org 19 Apr 14:31:13 ntpdate[16848]: the NTP socket is in use, exiting [root@m01 ~]# 1.2 install docker 1.2.1卸载旧版 docker 并手动删除/var/lib/docker 目录 [root@m01 ~]# sudo yum remove docker \ > > > > > > > > > docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
Loaded plugins: fastestmirror, langpacks No Match for argument: docker No Match for argument: docker-client No Match for argument: docker-client-latest No Match for argument: docker-common No Match for argument: docker-latest No Match for argument: docker-latest-logrotate No Match for argument: docker-logrotate No Match for argument: docker-selinux No Match for argument: docker-engine-selinux No Match for argument: docker-engine No Packages marked for removal [root@m01 ~]# [root@m01 ~]# rm -rf /var/lib/docker/ [root@m01 ~]# 1.2.2set up docker repository 1.2.2.1.Install required packages. yum-utils provides the yum-config-managerutility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver. $ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 1.2.2.2.Use the following command to set up the stable repository. $ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
1.2.3安装 docker [root@s02 ~]# sudo yum install -y docker-ce docker-ce-cli containerd.io Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package 1:docker-ce-cli-18.09.5-3.el7.x86_64 already installed and latest version Package containerd.io-1.2.5-3.1.el7.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package docker-ce.x86_64 3:18.09.5-3.el7 will be installed --> >= 3:docker-ce-18.09.5-3.el7.x86_64 --> Running transaction check ---> Package container-selinux.noarch 2:2.74-1.el7 will be installed --> Finished Dependency Resolution container-selinux Dependency: Processing 2.9 for package: Dependencies Resolved =========================================================== =========================================================== =========================================================== Arch Package Version Repository Size =========================================================== =========================================================== =========================================================== Installing: docker-ce 3:18.09.5-3.el7 19 M Installing for dependencies: container-selinux 2:2.74-1.el7 38 k x86_64 docker-ce-stable noarch extras Transaction Summary =========================================================== =========================================================== =========================================================== Install 1 Package (+1 Dependent package) Total size: 19 M
Total download size: 19 M Installed size: 81 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. docker-ce-18.09.5-3.el7.x86_64.rpm | 19 MB 00:00:04 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing 1/2 setsebool: SELinux is disabled. Installing 2/2 Verifying 1/2 Verifying 2/2 Installed: : : 2:container-selinux-2.74-1.el7.noarch 3:docker-ce-18.09.5-3.el7.x86_64 : : 2:container-selinux-2.74-1.el7.noarch 3:docker-ce-18.09.5-3.el7.x86_64 docker-ce.x86_64 3:18.09.5-3.el7 Dependency Installed: container-selinux.noarch 2:2.74-1.el7 from /etc/systemd/system/multi-user.target.wants/docker.service Complete! [root@s02 ~]# sudo systemctl start docker [root@s02 ~]# sudo systemctl enable docker Created symlink /usr/lib/systemd/system/docker.service. [root@s02 ~]# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e Status: Downloaded newer image for hello-world:latest to Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/ [root@s02 ~]# 1.3 installing kubeadm 1.3.1前置要求  2 GB or more of RAM per machine (any less will leave little room for your apps)  2 CPUs or more  Full network connectivity between all machines in the cluster (public or private network is fine)  Unique hostname, MAC address, and product_uuid for every node. See here for more details.  Certain ports are open on your machines. See here for more details.  Swap disabled. You MUST disable swap in order for the kubelet to work properly. 1.3.2检查要求的端口 Master node(s) Protocol Direction Port Range Purpose Used By TCP Inbound 6443* Kubernetes API server All
Protocol Direction Port Range Purpose Used By TCP TCP TCP TCP Inbound 2379-2380 etcd server client API kube-apiserver, etcd Inbound 10250 Kubelet API Self, Control plane Inbound 10251 kube-scheduler Self Inbound 10252 kube-controller-manager Self Worker node(s) Protocol Direction Port Range Purpose Used By TCP TCP Inbound 10250 Kubelet API Self, Control plane Inbound 30000-32767 NodePort Services** All ** Default port range for NodePort Services. Any port numbers marked with * are overridable, so you will need to ensure any custom ports you provide are also open. Although etcd ports are included in master nodes, you can also host your own etcd cluster externally or on custom ports. The pod network plugin you use (see below) may also require certain ports to be open. Since this differs with each pod network plugin, please see the documentation for the plugins about what port(s) those need. 1.3.3关闭 SELinux [root@redis-test2 ~]# clear [root@redis-test2 ~]# setenforce 0 setenforce: SELinux is disabled [root@redis-test2 /etc/selinux/config ~]# sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/'
[root@redis-test2 ~]# 1.3.4开启 CentOS 网桥 [root@redis-test2 ~]# cat < /etc/sysctl.d/k8s.conf > net.bridge.bridge-nf-call-ip6tables = 1 > net.bridge.bridge-nf-call-iptables = 1 > EOF [root@redis-test2 ~]# sysctl --system * Applying /usr/lib/sysctl.d/00-system.conf ... net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 * Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ... kernel.yama.ptrace_scope = 0 * Applying /usr/lib/sysctl.d/50-default.conf ... kernel.sysrq = 16 kernel.core_uses_pid = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.default.promote_secondaries = 1 net.ipv4.conf.all.promote_secondaries = 1 fs.protected_hardlinks = 1 fs.protected_symlinks = 1 * Applying /etc/sysctl.d/99-sysctl.conf ... * Applying /etc/sysctl.d/k8s.conf ... net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 * Applying /etc/sysctl.conf ... [root@redis-test2 ~]# 1.3.5准备 k8s 的国内 yum 源 [root@redis-test2 ~]# cat < /etc/yum.repos.d/kubernetes.repo > [kubernetes] > name=Kubernetes > baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 > enabled=1 > gpgcheck=0 > EOF
分享到:
收藏