# 本文档基于CentOS7.6发行版最小化安装部署

# 环境准备:
IP hostname configuration role
192.168.200.141 LB1 1C2G LB/VIP:192.168.200.20
192.168.200.142 LB2 1C2G LB
192.168.200.161 master01-161 4C8G docker-ce/kk
192.168.200.162 master02-162 4C8G docker-ce/
192.168.200.163 master03-163 4C8G docker-ce/

# 实验环境使用nginx+keepalived做负载均衡高可用,也可使用官方文档中用的haproxy+keepalived
yum -y install nginx keepalived
yum -y install nginx-all-modules.noarch

# nginx配置文件stream段配置
stream {
log_format proxy '$time_local|$remote_addr|$upstream_addr|$protocol|$status|'
'$session_time|$upstream_connect_time|$bytes_sent|$bytes_received|'
'$upstream_bytes_sent|$upstream_bytes_received' ;
upstream api_server {
least_conn;
server 192.168.200.161:6443 max_fails=3 fail_timeout=5s;
server 192.168.200.162:6443 max_fails=3 fail_timeout=5s;
server 192.168.200.163:6443 max_fails=3 fail_timeout=5s;
}
server {
listen 6443;
proxy_pass api_server;
access_log /var/log/nginx/proxy.log proxy;
}
}

# 安装依赖
yum -y install conntrack socat

# 配置环境变量 ps:不设置默认会从github和google拉取镜像
export KKZONE=cn

# 下载 KubeKey
curl -sfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh -
chmod +x kk

# 生成配置文件
./kk create config --with-kubernetes v1.20.4 --with-kubesphere v3.1.1

# 自定义配置文件
vim config-sample.yaml
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: config-sample
spec:
hosts:
- {name: master1, address: 192.168.60.152, internalAddress: 192.168.60.152, user: root, password: P@ssw0rd}
- {name: worker1, address: 192.168.60.153, internalAddress: 192.168.60.153, user: root, password: P@ssw0rd}
- {name: worker2, address: 192.168.60.154, internalAddress: 192.168.60.154, user: root, password: P@ssw0rd}
roleGroups:
etcd:
- master1
master:
- master1
worker:
- worker1
- worker2
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: "6443"

# 创建集群
./kk create cluster -f config-sample.yaml

# 查看安装日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

# 删除集群
./kk delete cluster -f config-sample.yaml

# kubectl命令补全
apt-get install bash-completion
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl

官方文档:
https://kubesphere.io/zh/docs/installing-on-linux/