安装Rancher折腾k8s

1、安装install_rancher.sh

sudo docker run -d --restart=unless-stopped \
-p 80:80 -p 443:443 \
-v /home/ubuntu/WorkSpace/Rancher_Space/rancher:/var/lib/rancher/ \
-v /home/ubuntu/WorkSpace/Rancher_Space/log:/var/log/auditlog \
-e CATTLE_SYSTEM_CATALOG=bundled \
-e AUDIT_LEVEL=3 \
rancher/rancher:stable
 

2、进入http://Yourip 一路设置

2.1、设置admin密码

2.2、可在进入系统后右下角可修改语言

2.3、添加集群,点击Add Cluster

2.4、选择From existing nodes (Custom)

2.5、设置Cluster Name

2.6、根据需要勾选,我单机部署,etcd、Control Plane、Worker都勾选了

2.7、拷贝下面的脚本,到命令行执行

sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.3.5 --server https://YourIP --token l7fccvg8qn64wwml4z5mj2nsn7j2vr6wkzskt9hzmsn8vwxflb46hc --ca-checksum c9d16d3eee4471fbf14c6b725e18be888f82effb14f4145b3b87666cfe1debab --etcd --controlplane --worker

2.8、创建完成后,如下State 为Active状态,即创建成功

 

2.9、如果失败,执行clear_rancher.sh清理一下

#!/bin/bash
#list all rancher and k8s docker iamges,then stop them
docker ps|grep -i "rancher\|k8s"|awk '{print $1}'|xargs  -i docker stop {}

#remove the contains
docker ps -a|grep -i "rancher\|k8s"|awk '{print $1}'|xargs -i docker rm {}

#remove the images
docker images |grep rancher|awk '{print $3}'|xargs  -i docker rmi {}

#remove the rancher space
echo 1 |sudo -S rm -r /home/ubuntu/WorkSpace/Rancher_Space/rancher
echo 1 |sudo -S rm -rf /home/ubuntu/WorkSpace/Rancher_Space/var
echo 1 |sudo -S rm -rf /home/ubuntu/WorkSpace/Rancher_Space/etc
echo 1 |sudo -S rm -rf /var/lib/etcd/*
echo 1 |sudo -S rm -rf /etc/kubernetes/*
echo 1 |sudo -S rm -rf /etc/ceph \
       /etc/cni \
       /etc/kubernetes \
       /opt/cni \
       /opt/rke \
       /run/secrets/kubernetes.io \
       /run/calico \
       /run/flannel \
       /var/lib/calico \
       /var/lib/etcd \
       /var/lib/cni \
       /var/lib/kubelet \
       /var/lib/rancher/rke/log \
       /var/log/containers \
       /var/log/pods \
       /var/run/calico
echo 1 |sudo -S ip link delete 虚拟network interface
 

3、到此已经安装完成rancher,本人多次安装rancher或者版本升级,都折腾一通时间,有点烦了,所以找个stable版本用一段时间,存成tar包保存起来,等下次在别的机器上部署时,直接load进来,再安装,基本上几分钟就ok

3.1、备份 savedockeriamge.sh
docker save -o rancher_rancher-agent_v2.3.5.tar rancher/rancher-agent:v2.3.5
docker save -o rancher_rancher_stable.tar rancher/rancher:stable
docker save -o rancher_hyperkube_v1.17.2-rancher1.tar rancher/hyperkube:v1.17.2-rancher1
docker save -o rancher_rke-tools_v0.1.52.tar rancher/rke-tools:v0.1.52
docker save -o rancher_calico-node_v3.10.2.tar rancher/calico-node:v3.10.2
docker save -o rancher_calico-cni_v3.10.2.tar rancher/calico-cni:v3.10.2
docker save -o rancher_calico-pod2daemon-flexvol_v3.10.2.tar rancher/calico-pod2daemon-flexvol:v3.10.2
docker save -o rancher_coreos-etcd_v3.4.3-rancher1.tar rancher/coreos-etcd:v3.4.3-rancher1
docker save -o rancher_nginx-ingress-controller_nginx-0.25.1-rancher1.tar rancher/nginx-ingress-controller:nginx-0.25.1-rancher1
docker save -o rancher_kube-api-auth_v0.1.3.tar rancher/kube-api-auth:v0.1.3
docker save -o rancher_coreos-flannel_v0.11.0.tar rancher/coreos-flannel:v0.11.0
docker save -o rancher_pause_3.1.tar rancher/pause:3.1


docker save -o rancher_coredns-coredns_1.6.5.tar rancher/coredns-coredns:1.6.5
docker save -o rancher_metrics-server_v0.3.6.tar rancher/metrics-server:v0.3.6
docker save -o rancher_cluster-proportional-autoscaler_1.7.1.tar rancher/cluster-proportional-autoscaler:1.7.1
docker save -o rancher_nginx-ingress-controller-defaultbackend_1.5-rancher1.tar rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1
 

3.2、在别的机器上下次安装之前,先加载 loaddockerimage.sh

docker load -i rancher_rancher-agent_v2.3.5.tar
docker load -i rancher_rancher_stable.tar
docker load -i rancher_hyperkube_v1.17.2-rancher1.tar
docker load -i rancher_rke-tools_v0.1.52.tar
docker load -i rancher_calico-node_v3.10.2.tar
docker load -i rancher_calico-cni_v3.10.2.tar
docker load -i rancher_calico-pod2daemon-flexvol_v3.10.2.tar
docker load -i rancher_coreos-etcd_v3.4.3-rancher1.tar
docker load -i rancher_nginx-ingress-controller_nginx-0.25.1-rancher1.tar
docker load -i rancher_kube-api-auth_v0.1.3.tar
docker load -i rancher_coreos-flannel_v0.11.0.tar
docker load -i rancher_pause_3.1.tar

docker load -i rancher_coredns-coredns_1.6.5.tar
docker load -i rancher_metrics-server_v0.3.6.tar
docker load -i rancher_cluster-proportional-autoscaler_1.7.1.tar
docker load -i rancher_nginx-ingress-controller-defaultbackend_1.5-rancher1.tar

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐