kube 快速安装

Catálogo
  1. 1. More Faster 方案: KubeKey
    1. 1.1. 下载 KubeKey
    2. 1.2. 创建配置
    3. 1.3. *安装单集群
    4. 1.4. 修改配置
    5. 1.5. 安装系统
  2. 2. 宿主机设置
    1. 2.1. 关闭 交换分区
    2. 2.2. 设置Hostname和host
    3. 2.3. 本机搞个VPN & 设置好代理
    4. 2.4. 设置Docker代理
  3. 3. K8s 安装
    1. 3.1. 安装Kubadmin
    2. 3.2. 初始化节点
    3. 3.3. 安装网络插件

More Faster 方案: KubeKey

下载 KubeKey

1
2
3
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v1.0.1 sh -
chmod +x kk

创建配置

1
./kk create config --with-kubernetes v1.17.9

*安装单集群

1
./kk create cluster --with-kubernetes v1.17.9

修改配置

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
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: node1, address: 172.16.0.2, internalAddress: 172.16.0.2, port: 8022, user: ubuntu, password: Qcloud@123} # Assume that the default port for SSH is 22, otherwise add the port number after the IP address as above
- {name: node2, address: 172.16.0.3, internalAddress: 172.16.0.3, password: Qcloud@123} # the default root user
- {name: node3, address: 172.16.0.4, internalAddress: 172.16.0.4, privateKeyPath: "~/.ssh/id_rsa"} # password-less login with SSH keys
roleGroups:
etcd:
- node1
master:
- node1
- node[2:10] # the nodes from node2, node3,..., to node10
worker:
- node1
- node[10:100]
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: 6443
kubernetes:
version: v1.17.9
imageRepo: kubesphere
clusterName: cluster.local
masqueradeAll: false # masqueradeAll tells kube-proxy to SNAT everything if using the pure iptables proxy mode. [Default: false]
maxPods: 110 # maxPods is the number of pods that can run on this Kubelet. [Default: 110]
nodeCidrMaskSize: 24 # internal network node size allocation. This is the size allocated to each node on your network. [Default: 24]
proxyMode: ipvs # mode specifies which proxy mode to use. [Default: ipvs]
network:
plugin: calico
calico:
ipipMode: Always # IPIP Mode to use for the IPv4 POOL created at start up. If set to a value other than Never, vxlanMode should be set to "Never". [Always | CrossSubnet | Never] [Default: Always]
vxlanMode: Never # VXLAN Mode to use for the IPv4 POOL created at start up. If set to a value other than Never, ipipMode should be set to "Never". [Always | CrossSubnet | Never] [Default: Never]
vethMTU: 1440 # The maximum transmission unit (MTU) setting determines the largest packet size that can be transmitted through your network. [Default: 1440]
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
registry:
registryMirrors: []
insecureRegistries: []
privateRegistry: ""
addons: []

安装系统

1
./kk create cluster -f xxx.yaml

宿主机设置

关闭 交换分区

1
swapoff -a

设置Hostname和host

1
2
hostnamectl set-hostname <your-name>
vim /etc/hosts

本机搞个VPN & 设置好代理

1
2
3
4
export http_proxy=http://naso.yannxia.top:8123
export https_proxy=http://naso.yannxia.top:8123
export ftp_proxy=http://naso.yannxia.top:8123
export no_proxy=localhost,127.0.0.0,127.0.1.1,127.0.1.1,10.0.0.0/8,172.16.0.0/16,192.168.0.0/16,mirrors.aliyun.com

设置Docker代理

1
2
3
4
5
6
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://naso.yannxia.top:8123/"
Environment="NO_PROXY=localhost,127.0.0.0/8,10.0.0.0/8,192.168.0.0/16,172.16.0.0/16,su0d0vi9.mirror.aliyuncs.com"
systemctl daemon-reload && systemctl restart docker

K8s 安装

安装Kubadmin

1
2
3
4
5
6
7
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl

初始化节点

1
kubeadm init --apiserver-advertise-address 172.16.80.135 --pod-network-cidr=192.168.0.0/16

安装网络插件

1
kubectl apply -f https://docs.projectcalico.org/v3.11/manifests/calico.yaml