环境准备
当前 192.168.43.10[1:3] 是 master 节点 ,192.168.43.10[4:5] 是 node 节点。每个节点都需要安装 python。1
git clone https://github.com/itswl/kubeasz.git
修改 ansible 中 hosts 文件,修改后如下。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68# 'etcd' cluster should have odd member(s) (1,3,5,...)
# variable 'NODE_NAME' is the distinct name of a member in 'etcd' cluster
[etcd]
192.168.43.101 NODE_NAME=etcd1
192.168.43.102 NODE_NAME=etcd2
192.168.43.103 NODE_NAME=etcd3
192.168.43.104 NODE_NAME=etcd4
192.168.43.105 NODE_NAME=etcd5
# master node(s)
[kube-master]
192.168.43.101
192.168.43.102
192.168.43.103
# work node(s)
[kube-node]
192.168.43.104
192.168.43.105
# [optional] harbor server, a private docker registry
# 'NEW_INSTALL': 'yes' to install a harbor server; 'no' to integrate with existed one
# 'SELF_SIGNED_CERT': 'no' you need put files of certificates named harbor.pem and harbor-key.pem in directory 'down'
[harbor]
192.168.43.102 HARBOR_DOMAIN="harbor.yourdomain.com" NEW_INSTALL=no SELF_SIGNED_CERT=yes
# [optional] loadbalance for accessing k8s from outside
[ex-lb]
#192.168.43.106 LB_ROLE=backup EX_APISERVER_VIP=192.168.43.100 EX_APISERVER_PORT=8443
#192.168.43.107 LB_ROLE=backup EX_APISERVER_VIP=192.168.43.100 EX_APISERVER_PORT=8443
#192.168.43.108 LB_ROLE=master EX_APISERVER_VIP=192.168.43.100 EX_APISERVER_PORT=8443
# [optional] ntp server for the cluster
[chrony]
192.168.43.101
[all:vars]
# --------- Main Variables ---------------
# Cluster container-runtime supported: docker, containerd
CONTAINER_RUNTIME="docker"
# Network plugins supported: calico, flannel, kube-router, cilium, kube-ovn
CLUSTER_NETWORK="flannel"
# Service proxy mode of kube-proxy: 'iptables' or 'ipvs'
PROXY_MODE="ipvs"
# K8S Service CIDR, not overlap with node(host) networking
SERVICE_CIDR="10.68.0.0/16"
# Cluster CIDR (Pod CIDR), not overlap with node(host) networking
CLUSTER_CIDR="172.20.0.0/16"
# NodePort Range
NODE_PORT_RANGE="20000-40000"
# Cluster DNS Domain
CLUSTER_DNS_DOMAIN="cluster.local."
# -------- Additional Variables (don't change the default value right now) ---
# Binaries Directory
bin_dir="/opt/kube/bin"
# CA and other components cert/key Directory
ca_dir="/etc/kubernetes/ssl"
# Deploy Directory (kubeasz workspace)
base_dir="/etc/ansible"
安装
执行以下命令1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# 分步安装
ansible-playbook 01.prepare.yml
ansible-playbook 02.etcd.yml
ansible-playbook 03.docker.yml
ansible-playbook 04.kube-master.yml
ansible-playbook 05.kube-node.yml
ansible-playbook 06.network.yml
ansible-playbook 07.cluster-addon.yml
# 一步安装
#ansible-playbook 90.setup.yml
[可选]对集群所有节点进行操作系统层面的安全加固 ansible-playbook roles/os-harden/os-harden.yml 详情请参考os-harden项目 https://github.com/dev-sec/ansible-os-hardening
# 卸载
ansible-playbook 99.clean.yml
遇到问题,定位查日志等解决
安装完成后1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25[root@k8s01 ansible]# kubectl get node
NAME STATUS ROLES AGE VERSION
192.168.43.101 Ready,SchedulingDisabled master 2m17s v1.18.3
192.168.43.102 Ready,SchedulingDisabled master 2m18s v1.18.3
192.168.43.103 Ready,SchedulingDisabled master 2m18s v1.18.3
192.168.43.104 Ready node 97s v1.18.3
192.168.43.105 Ready node 96s v1.18.3
[root@k8s01 ansible]# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-65dbdb44db-d7tpb 1/1 Running 0 62s
kube-system dashboard-metrics-scraper-545bbb8767-zpmfw 1/1 Running 0 43s
kube-system kube-flannel-ds-amd64-7f45j 1/1 Running 0 83s
kube-system kube-flannel-ds-amd64-hp74d 1/1 Running 0 83s
kube-system kube-flannel-ds-amd64-lfnqc 1/1 Running 0 83s
kube-system kube-flannel-ds-amd64-wcpgm 1/1 Running 0 83s
kube-system kube-flannel-ds-amd64-zqgk4 1/1 Running 0 83s
kube-system kubernetes-dashboard-65665f84db-h5tzk 1/1 Running 0 43s
kube-system metrics-server-869ffc99cd-8l9lk 1/1 Running 0 59s
[root@k8s01 ansible]# kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.68.0.1 <none> 443/TCP 22m
kube-system dashboard-metrics-scraper ClusterIP 10.68.99.51 <none> 8000/TCP 19m
kube-system kube-dns ClusterIP 10.68.0.2 <none> 53/UDP,53/TCP,9153/TCP 20m
kube-system kubernetes-dashboard NodePort 10.68.78.245 <none> 443:39370/TCP 19m
kube-system metrics-server ClusterIP 10.68.252.186 <none> 443/TCP 20m
安装记录
1 | [root@k8s01 ansible]# ansible-playbook 90.setup.yml |