文章目录
- 配置基础设施
- 安装k3s集群环境
- 安装k3s(所有k3s节点)
- 安装kubectl
- 使用helm3安装rancher
- 安装helm3
- 添加helm chart仓库,并为rancher创建 namespace
- 安装 cert-manager
- 安装rancher
配置基础设施
本示例采用3台linux服务器进行测试,其中一台负责安装mysql和nginx (node ),另外两台作为k3s节点(node-k3s1 node-k3s2)
-
linux服务器(至少两个节点),并设置单独的主机名
#设置主机名 hostnamectl set-hostname node #开放相关端口 k3s(6443/tcp 8472/udp) #centos7 firewall-cmd --permanent --zone=public --add-port=22/tcp firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --permanent --zone=public --add-port=443/tcp firewall-cmd --permanent --zone=public --add-port=6443/tcp firewall-cmd --permanent --zone=public --add-port=2379-2380/tcp firewall-cmd --permanent --zone=public --add-port=10250-10256/tcp firewall-cmd --permanent --zone=public --add-port=30000-32767/tcp firewall-cmd --permanent --zone=public --add-port=30000-32767/udp firewall-cmd --permanent --zone=public --add-port=8472/udp firewall-cmd --reload
-
外部数据库(mysql 用于存储集群数据)
-
负载均衡器(将流量转发到个节点)
ps: Docker 安装 (centos7) docker 常用软件安装 nginx mysql
安装k3s集群环境
安装k3s(所有k3s节点)
#在所有 Linux 节点上,运行以下命令以启动 K3s Server 并将其连接到外部数据库
curl -sfL https://get. | sh -s - server \
--datastore-endpoint="mysql://username:password@tcp(hostname:3306)/database-name"
#国内用户加速安装脚本
curl -sfL /k3s/ | INSTALL_K3S_MIRROR=cn sh -s - server \
--datastore-endpoint="mysql://username:password@tcp(hostname:3306)/database-name"
#如遇警告,请按提示执行
#[ERROR] Failed to find the k3s-selinux policy, please install:
# yum install -y container-selinux selinux-policy-base
# rpm -i /k3s-selinux-0.1.1-rc1.
#警告:/var/tmp/: 头V4 RSA/SHA1 Signature, 密钥 ID e257814a: NOKEY
#test 安装完整测试
sudo k3s kubectl get nodes
安装kubectl
#下载kubectl二进制文件 注意替换版本号
curl -LO /kubernetes-release/release/v1.10.0/bin/linux/amd64/kubectl
#如不确定版本,以下最新版本
curl -LO /kubernetes-release/release/$(curl -s /kubernetes-release/release/)/bin/linux/amd64/kubectl
#赋予执行权限
chmod +x ./kubectl
#将其移动到bin目录下
sudo mv ./kubectl /usr/local/bin/kubectl
#test 检查
kubectl get pods --all-namespaces
使用helm3安装rancher
安装helm3
#安装helm3
wget /helm-v3.1.
tar zxvf helm-v3.1.
cd linux-amd64
cp helm /usr/local/bin/
#test
helm version
# 设置kubeconfig ,也可helm调用时指定 helm --kubeconfig /etc/rancher/k3s/
export KUBECONFIG=/etc/rancher/k3s/
添加helm chart仓库,并为rancher创建 namespace
# 添加含有 Rancher Chart 的 Helm Chart 仓库
# latest: 推荐在尝试新功能时使用。
# stable: 推荐生产环境中使用。(推荐)
# alpha: 未来版本的实验性预览。
helm repo add rancher-stable /server-charts/stable
#为 Rancher 创建 Namespace
kubectl create namespace cattle-system
安装 cert-manager
#如果您使用自己的证书文件 `=secret`或者使用外部 TLS 负载均衡器可以跳过此步骤
# 安装 CustomResourceDefinition 资源
kubectl apply --validate=false -f /jetstack/cert-manager/releases/download/v0.15.0/
# 为 cert-manager 创建命名空间
kubectl create namespace cert-manager
# 添加 Jetstack Helm 仓库
helm repo add jetstack
# 更新本地 Helm chart 仓库缓存
helm repo update
# 安装 cert-manager Helm chart
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--version v0.15.0
安装rancher
# 本次测试示例使用 Rancher 生成的自签名证书,其他方式请参考 /docs/installation/k8s-install/helm-rancher/_index
# hostname 负载均衡器的 DNS 名称(域名) stable <CHART_REPO>
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--set hostname=
#等待rancher运行校验
kubectl -n cattle-system rollout status deploy/rancher
#deployment "rancher" successfully rolled out