进行node节点安装部署
3.6.1 复制二进制包
代码语言:javascript复制cd ../kubernetes/server/bin/
cp kubelet kube-proxy /app/kubernetes/bin/
scp kubelet kube-proxy k8s-node-1:/app/kubernetes/bin/
scp kubelet kube-proxy k8s-node-2:/app/kubernetes/bin/
3.6.2 创建角色绑定
代码语言:javascript复制kubectl create clusterrolebinding kubelet-bootstrap
--clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
3.6.3 创建 kubelet bootstrapping kubeconfig 文件
设置集群参数
代码语言:javascript复制kubectl config set-cluster kubernetes
--certificate-authority=/app/kubernetes/ssl/ca.pem
--embed-certs=true
--server=https://192.168.189.139:6443
--kubeconfig=bootstrap.kubeconfig
设置客户端认证参数
代码语言:javascript复制kubectl config set-credentials kubelet-bootstrap
--token=8fa4488b7751e2ba9f58555a8cb0cef4
--kubeconfig=bootstrap.kubeconfig
### 注意::--token的参数为上篇中的kube-apiserver
### 使用的客户端 token 文件中的那个token
设置上下文参数
代码语言:javascript复制 kubectl config set-context default
--cluster=kubernetes
--user=kubelet-bootstrap
--kubeconfig=bootstrap.kubeconfig
选择默认上下文
代码语言:javascript复制kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
scp bootstrap.kubeconfig /app/kubernetes/cfg/
scp bootstrap.kubeconfig k8s-node-1:/app/kubernetes/cfg/
scp bootstrap.kubeconfig k8s-node-2:/app/kubernetes/cfg/
3.6.4 部署kubelet
代码语言:javascript复制# 设置CNI支持
mkdir -p /etc/cni/net.d
vim /etc/cni/net.d/10-default.conf
{
"name": "flannel",
"type": "flannel",
"delegate": {
"bridge": "docker0",
"isDefaultGateway": true,
"mtu": 1400
}
}
# 创建kubelet目录
mkdir /var/lib/kubelet
创建kubelet启动服务配置
代码语言:javascript复制vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
WorkingDirectory=/var/lib/kubelet
ExecStart=/app/kubernetes/bin/kubelet
--address=192.168.189.139
--hostname-override=192.168.189.139
--pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0
--experimental-bootstrap-kubeconfig=/app/kubernetes/cfg/bootstrap.kubeconfig
--kubeconfig=/app/kubernetes/cfg/kubelet.kubeconfig
--cert-dir=/app/kubernetes/ssl
--network-plugin=cni
--cni-conf-dir=/etc/cni/net.d
--cni-bin-dir=/app/kubernetes/bin/cni
--cluster-dns=10.1.0.2
--cluster-domain=cluster.local.
--hairpin-mode hairpin-veth
--allow-privileged=true
--fail-swap-on=false
--logtostderr=true
--v=2
--logtostderr=false
--log-dir=/app/kubernetes/log
Restart=on-failure
RestartSec=5
启动服务
代码语言:javascript复制systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
systemctl status kubelet
在其他机器上创建下面2个文件夹
代码语言:javascript复制mkdir -p /etc/cni/net.d
mkdir /var/lib/kubelet
在主节点使用下面命令分发
代码语言:javascript复制scp /etc/cni/net.d/10-default.conf k8s-node-1:/etc/cni/net.d/10-default.conf
scp /etc/cni/net.d/10-default.conf k8s-node-2:/etc/cni/net.d/10-default.conf
下面2个文件要去对应机器修改IP
代码语言:javascript复制scp /usr/lib/systemd/system/kubelet.service
k8s-node-1:/usr/lib/systemd/system/kubelet.service
scp /usr/lib/systemd/system/kubelet.service
k8s-node-2:/usr/lib/systemd/system/kubelet.service
# 使用下面的命令,里面的两个IP都改为当前IP
vim /usr/lib/systemd/system/kubelet.service
在各个机器启动服务
代码语言:javascript复制systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
systemctl status kubelet
查看csr请求
代码语言:javascript复制kubectl get csr
结果如下:
代码语言:javascript复制[root@k8s-master bin]# kubectl get csr
NAME AGE REQUESTOR CONDITION
node-csr-M7NH4jxhj... 8m4s kubelet-bootstrap Pending
node-csr-XjMnA02kn... 30s kubelet-bootstrap Pending
node-csr-uIqmVSeTF... 26s kubelet-bootstrap Pending
通过kubelet 的 TLS 证书请求
代码语言:javascript复制kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs
kubectl certificate approve
kubectl get node
3.6.5 部署kube-proxy
配置kube-proxy使用LVS
代码语言:javascript复制yum install -y ipvsadm ipset conntrack
创建 kube-proxy 证书请求
代码语言:javascript复制vim kube-proxy-csr.json
{
"CN": "system:kube-proxy",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
生成证书
代码语言:javascript复制cfssl gencert -ca=/app/kubernetes/ssl/ca.pem
-ca-key=/app/kubernetes/ssl/ca-key.pem
-config=/app/kubernetes/ssl/ca-config.json
-profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy
复制证书到所有node节点
代码语言:javascript复制cp kube-proxy*.pem /app/kubernetes/ssl/
scp kube-proxy*.pem k8s-node-1:/app/kubernetes/ssl/
scp kube-proxy*.pem k8s-node-2:/app/kubernetes/ssl/
创建kube-proxy配置文件
代码语言:javascript复制kubectl config set-cluster kubernetes
--certificate-authority=/app/kubernetes/ssl/ca.pem
--embed-certs=true
--server=https://192.168.189.139:6443
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-credentials kube-proxy
--client-certificate=/app/kubernetes/ssl/kube-proxy.pem
--client-key=/app/kubernetes/ssl/kube-proxy-key.pem
--embed-certs=true
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-context default
--cluster=kubernetes
--user=kube-proxy
--kubeconfig=kube-proxy.kubeconfig
kubectl config use-context default
--kubeconfig=kube-proxy.kubeconfig
分发kubeconfig配置文件
代码语言:javascript复制scp kube-proxy.kubeconfig /app/kubernetes/cfg/
scp kube-proxy.kubeconfig k8s-node-1:/app/kubernetes/cfg/
scp kube-proxy.kubeconfig k8s-node-2:/app/kubernetes/cfg/
配置启动服务
#各节点都执行 并修改对应IP
代码语言:javascript复制mkdir /var/lib/kube-proxy
创建 kube-proxy.service
代码语言:javascript复制vim /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
[Service]
WorkingDirectory=/var/lib/kube-proxy
ExecStart=/app/kubernetes/bin/kube-proxy
--bind-address=192.168.189.139
--hostname-override=192.168.189.139
--kubeconfig=/app/kubernetes/cfg/kube-proxy.kubeconfig
--masquerade-all
--feature-gates=SupportIPVSProxyMode=true
--proxy-mode=ipvs
--ipvs-min-sync-period=5s
--ipvs-sync-period=5s
--ipvs-scheduler=rr
--logtostderr=true
--v=2
--logtostderr=false
--log-dir=/app/kubernetes/log
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
同步到其他节点
代码语言:javascript复制scp /usr/lib/systemd/system/kube-proxy.service
k8s-node-1:/usr/lib/systemd/system/
scp /usr/lib/systemd/system/kube-proxy.service
k8s-node-2:/usr/lib/systemd/system/
修改kube-proxy.service中的IP
vim /usr/lib/systemd/system/kube-proxy.service
各节点都启动服务
代码语言:javascript复制systemctl daemon-reload
systemctl enable kube-proxy && systemctl start kube-proxy
systemctl status kube-proxy
3.7 配置flannel网络
3.7.1 生成flannel证书
代码语言:javascript复制vim flanneld-csr.json
{
"CN": "flanneld",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
3.7.2 生成证书
代码语言:javascript复制cfssl gencert -ca=/app/kubernetes/ssl/ca.pem
-ca-key=/app/kubernetes/ssl/ca-key.pem
-config=/app/kubernetes/ssl/ca-config.json
-profile=kubernetes flanneld-csr.json | cfssljson -bare flanneld
3.7.3 分发证书
代码语言:javascript复制cp flanneld*.pem /app/kubernetes/ssl/
scp flanneld*.pem k8s-node-1:/app/kubernetes/ssl/
scp flanneld*.pem k8s-node-2:/app/kubernetes/ssl/
3.7.4 下载Flannel软件包相关软件包
代码语言:javascript复制wget https://github.com/coreos/flannel/releases/download/v0.11.0/
flannel-v0.11.0-linux-amd64.tar.gz
tar xf flannel-v0.11.0-linux-amd64.tar.gz
cd flannel-v0.11.0-linux-amd64/
cp flanneld mk-docker-opts.sh /app/kubernetes/bin/
scp flanneld mk-docker-opts.sh k8s-node-1:/app/kubernetes/bin/
scp flanneld mk-docker-opts.sh k8s-node-2:/app/kubernetes/bin/
代码语言:javascript复制wget https://github.com/kubernetes/kubernetes/releases/download/v1.14.2/
kubernetes.tar.gz
tar xf kubernetes.tar.gz && cd kubernetes/cluster/centos/node/bin
cp remove-docker0.sh /app/kubernetes/bin/
scp remove-docker0.sh k8s-node-1:/app/kubernetes/bin/
scp remove-docker0.sh k8s-node-2:/app/kubernetes/bin/
3.7.5 配置flannel
代码语言:javascript复制vim /app/kubernetes/cfg/flannel
FLANNEL_ETCD="-etcd-endpoints=https://192.168.189.139:2379,
https://192.168.189.131:2379,https://192.168.189.132:2379"
FLANNEL_ETCD_KEY="-etcd-prefix=/kubernetes/network"
FLANNEL_ETCD_CAFILE="--etcd-cafile=/app/kubernetes/ssl/ca.pem"
FLANNEL_ETCD_CERTFILE="--etcd-certfile=/app/kubernetes/ssl/flanneld.pem"
FLANNEL_ETCD_KEYFILE="--etcd-keyfile=/app/kubernetes/ssl/flanneld-key.pem"
同步到其他节点
代码语言:javascript复制scp /app/kubernetes/cfg/flannel k8s-node-1:/app/kubernetes/cfg
scp /app/kubernetes/cfg/flannel k8s-node-2:/app/kubernetes/cfg
3.7.6 设置Flannel系统服务
代码语言:javascript复制vim /usr/lib/systemd/system/flannel.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
Before=docker.service
[Service]
EnvironmentFile=-/app/kubernetes/cfg/flannel
ExecStartPre=/app/kubernetes/bin/remove-docker0.sh
ExecStart=/app/kubernetes/bin/flanneld ${FLANNEL_ETCD} ${FLANNEL_ETCD_KEY} ${FLANNEL_ETCD_CAFILE} ${FLANNEL_ETCD_CERTFILE} ${FLANNEL_ETCD_KEYFILE}
ExecStartPost=/app/kubernetes/bin/mk-docker-apps.sh -d /run/flannel/docker
Type=notify
[Install]
WantedBy=multi-user.target
RequiredBy=docker.service
由于上面文件的配置ExecStartPost=/app/kubernetes/bin/mk-docker-apps.sh
需要将原来 /app/kubernetes/bin下的mk-docker-opts.sh重命名成mk-docker-apps.sh
代码语言:javascript复制mv mk-docker-opts.sh mk-docker-apps.sh
分发启动服务
代码语言:javascript复制scp /usr/lib/systemd/system/flannel.service
k8s-node-1:/usr/lib/systemd/system/flannel.service
scp /usr/lib/systemd/system/flannel.service
k8s-node-2:/usr/lib/systemd/system/flannel.service
3.7.7 flannel cni插件配置
代码语言:javascript复制wget https://github.com/containernetworking/plugins/releases/download/
v0.8.0/cni-plugins-linux-amd64-v0.8.0.tgz
mkdir /app/kubernetes/bin/cni
tar -zxf cni-plugins-linux-amd64-v0.8.0.tgz -C /app/kubernetes/bin/cni/
scp -r /app/kubernetes/bin/cni/ k8s-node-1:/app/kubernetes/bin/
scp -r /app/kubernetes/bin/cni/ k8s-node-2:/app/kubernetes/bin/
3.7.8 创建etcd的key
代码语言:javascript复制/app/kubernetes/bin/etcdctl --ca-file /app/kubernetes/ssl/ca.pem
--cert-file /app/kubernetes/ssl/flanneld.pem
--key-file /app/kubernetes/ssl/flanneld-key.pem
--no-sync -C https://192.168.189.139:2379,https://192.168.189.131:2379,
https://192.168.189.132:2379
mk /kubernetes/network/config '{ "Network": "10.2.0.0/16", "Backend": { "Type": "vxlan", "VNI": 1 }}' >/dev/null 2>&1
3.7.9 启动flannel
代码语言:javascript复制systemctl daemon-reload && systemctl start flannel
systemctl status flannel
3.7.10 修改docker启动服务
代码语言:javascript复制vim /usr/lib/systemd/system/docker.service
[Unit] #在Unit下面修改After和增加Requires
After=network-online.target firewalld.service flannel.service
Wants=network-online.target
Requires=flannel.service
[Service] #增加EnvironmentFile=-/run/flannel/docker
Type=notify
EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd $DOCKER_OPTS
3.7.11 分发到其它服务器
代码语言:javascript复制scp /usr/lib/systemd/system/docker.service
k8s-node-1:/usr/lib/systemd/system/docker.service
scp /usr/lib/systemd/system/docker.service
k8s-node-2:/usr/lib/systemd/system/docker.service
3.7.12 重启docker
代码语言:javascript复制systemctl daemon-reload && systemctl restart docker
====================================================
Kubernetes-1.14.2的源码包 kernel-ml-4.18.9.tar.gz 有百度云盘资源,链接:https://pan.baidu.com/s/1NZW2DV64DkybD6QI42lw7Q ; 提取码:t5bv
====================================================