目录
Kubernetes 简介:
Kubernetes是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效(powerful),Kubernetes提供了应用部署,规划,更新,维护的一种机制。
官方文档
参考:Kubernetes是什么 _ Kubernetes(K8S)中文文档_Kubernetes中文社区
1、服务器基本环境
名称 | IP | 系统版本 |
master | 192.168.44.128 | CentOS Linux release 7.9.2009 (Core) |
node1 | 192.168.44.130 | CentOS Linux release 7.9.2009 (Core) |
node2 | 192.168.44.129 | CentOS Linux release 7.9.2009 (Core) |
2、修改主机名
[root@master ~]# hostnamectl set-hostname master
[root@node1 ~]# hostnamectl set-hostname node1
[root@node2 ~]# hostnamectl set-hostname node2
3、内部域名解析:/etc/hosts
eg:node2和node1同master
[root@node2 ~]# cat <<EOF >> /etc/hosts
> 192.168.44.128 master
> 192.168.44.129 node2
> 192.168.44.130 node
> EOF
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.44.128 master
192.168.44.129 node2
192.168.44.130 node
4、关闭防火墙、Selinux及Swap(所有节点)
eg:node2 node1和master同master
[root@node2 ~]# systemctl stop firewalld && systemctl disable firewalld
[root@node2 ~]# setenforce 0
[root@node2 ~]# vim /etc/selinux/config
SELINUX=disabled
[root@node2 ~]# swapoff -a # 临时
[root@node2 ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
或者
[root@node2 ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
5、所有节点安装Docker
-
下载docker镜像
[root@master ~]# wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz
-
拷贝Docker文件到其它节点
[root@master ~]# for i in node1 node2; do scp docker-19.03.9.tgz root@$i:/root; done
-
解压(所有节点)
[root@master ~]# tar -xf docker-19.03.9.tgz && mv docker/* /usr/bin/
-
创建systemd文件管理docker(所有节点)
[root@master ~]# cat > /usr/lib/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
-
阿里云镜像加速器地址
-
创建docker配置文件
[root@master ~]# mkdir /etc/docker/
[root@master ~]# cat > /etc/docker/daemon.json << EOF
> {
> "registry-mirrors": ["https://e3bi90pi.mirror.aliyuncs.com"]
> }
> EOF
-
启动Docker及加入开机自启动(每个节点)
[root@master ~]# systemctl enable docker && systemctl start docker
[root@master ~]# docker info
Client:
Debug Mode: false
Plugins:
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc.)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.9
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.84GiB
Name: master
ID: CCZ4:7VX4:JWDV:BV5X:3BYX:HJSP:2TEP:DIC7:C6XG:I5YB:JSMA:AEGP
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://e3bi90pi.mirror.aliyuncs.com/
Live Restore Enabled: false
Product License: Community Engine