Rancher-k3s
description: ‘k3s是轻量的kubernets,内存占用少,系统以二进制形式运行且大小小于100MB. 本文主要详解介绍k3s高可用方案。’
安装
master安装
10.10.8.21~10.10.8.23 为master节点,需要安装mater相关的组件。
k3s官方提供了通过脚本install.sh安装方法。脚本下载好以后,添加如下内容。
- 考虑到安装速度,提前下载了指定版本的tar包到本地。
- –node-taint 参数配置节点反亲和性,即不调度节点到master上。
- –token 参数保证了所有master节点都含有相同的token.
- –cluster-init 在其中一个master节点上指定,作为master集群中的主节点.
- K3S_DATASTORE_ENDPOINT环境变量指定了etcd集群的地址。
#额外添加的内容
INSTALL_K3S_VERSION=v1.16.9
INSTALL_K3S_SKIP_DOWNLOAD=true
INSTALL_K3S_EXEC="server --docker --node-taint k3s-controlplane=true:NoExecute --no-deploy=traefik --token=x120952576 :--cluster-init --tls-san=10.10.8.21 --datastore-cafile=/etc/kubernetes/cert/ca.pem --datastore-certfile=/etc/etcd/cert/etcd.pem --datastore-keyfile=/etc/etcd/cert/etcd-key.pem"
export K3S_DATASTORE_ENDPOINT="http://10.10.8.21:2379"
echo "- - - - - - - - - -"
echo "Install K3S ${INSTALL_K3S_VERSION}"
echo "- - - - - - - - - -"
mkdir -p /var/lib/rancher/k3s/agent/images/
cp ./k3s-airgap-images-amd64-${INSTALL_K3S_VERSION}.tar.gz /var/lib/rancher/k3s/agent/images/
mkdir -p ~/.kube
[[ -f ~/.kube/config ]] && rm ~/.kube/config
ln -sf /etc/rancher/k3s/k3s.yaml ~/.kube/config
tar xzf k3s-bin-${INSTALL_K3S_VERSION}.tar.gz -C /usr/local/bin
#官方脚本
# Usage:
# curl ... | ENV_VAR=... sh -
# or
# ENV_VAR=... ./install.sh
#
从master节点配置如下:
INSTALL_K3S_VERSION=v1.16.9
INSTALL_K3S_SKIP_DOWNLOAD=true
K3S_TOKEN="x120952576"
INSTALL_K3S_EXEC="server --server https://10.10.8.21:6443 --token ${K3S_TOKEN} --docker --node-taint k3s-controlplane=true:NoExecute --no-deploy=traefik --tls-san=10.10.8.21 --datastore-cafile=/etc/kubernetes/cert/ca.pem --datastore-certfile=/etc/etcd/cert/etcd.pem --datastore-keyfile=/etc/etcd/cert/etcd-key.pem"
export K3S_DATASTORE_ENDPOINT="http://10.10.8.21:2379"
echo "- - - - - - - - - -"
echo "Install K3S ${INSTALL_K3S_VERSION}"
echo "- - - - - - - - - -"
mkdir -p /var/lib/rancher/k3s/agent/images/
cp ./k3s-airgap-images-amd64-${INSTALL_K3S_VERSION}.tar.gz /var/lib/rancher/k3s/agent/images/
mkdir -p ~/.kube
[[ -f ~/.kube/config ]] && rm ~/.kube/config
ln -sf /etc/rancher/k3s/k3s.yaml ~/.kube/config
tar xzf k3s-bin-${INSTALL_K3S_VERSION}.tar.gz -C /usr/local/bin
agent安装
- –server 指定主master节点的apiserver地址
INSTALL_K3S_VERSION=v1.16.9
INSTALL_K3S_SKIP_DOWNLOAD=true
INSTALL_K3S_EXEC="agent --docker --server https://10.10.8.21:6443 --token=x120952576"
echo "- - - - - - - - - -"
echo "Install K3S ${INSTALL_K3S_VERSION}"
echo "- - - - - - - - - -"
mkdir -p /var/lib/rancher/k3s/agent/images/
cp ./k3s-airgap-images-amd64-${INSTALL_K3S_VERSION}.tar.gz /var/lib/rancher/k3s/agent/images/
mkdir -p ~/.kube
[[ -f ~/.kube/config ]] && rm ~/.kube/config
ln -sf /etc/rancher/k3s/k3s.yaml ~/.kube/config
tar xzf k3s-bin-${INSTALL_K3S_VERSION}.tar.gz -C /usr/local/bin
etcd集群部署
etcd集群使用docker分别在mater三台机器上部署。
ETCD_VERSION=v3.4.9
TOKEN=my-etcd-token
CLUSTER_STATE=new
NAME_1=etcd-node-0
NAME_2=etcd-node-1
NAME_3=etcd-node-2
HOST_1=10.10.8.21
HOST_2=10.10.8.22
HOST_3=10.10.8.23
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
docker run -d -p 4001:4001 -p 2380:2380 -p 2379:2379 -v /data:/data.etcd -v /etc/etcd:/etc/etcd -v /etc/kubernetes:/etc/kubernetes --name etcd quay.io/coreos/etcd:${ETCD_VERSION} \
/usr/local/bin/etcd \
--name ${NAME_1} \
--data-dir=data.etcd \
--cert-file=/etc/etcd/cert/etcd.pem \
--key-file=/etc/etcd/cert/etcd-key.pem \
--trusted-ca-file=/etc/kubernetes/cert/ca.pem \
--peer-cert-file=/etc/etcd/cert/etcd.pem \
--peer-key-file=/etc/etcd/cert/etcd-key.pem \
--peer-trusted-ca-file=/etc/kubernetes/cert/ca.pem \
--peer-client-cert-auth \
--client-cert-auth \
--initial-advertise-peer-urls http://10.10.8.21:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--advertise-client-urls http://10.10.8.21:2379,http://10.10.8.21:4001 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE}
文档信息
- 本文作者:Beast
- 本文链接:https://beastpu.github.io/2019/01/18/k3s/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)