Installation and use of Rancher 2.x
Article Directory
-
- Installation and use of Rancher 2.x
1. Introduction to Rancher
Rancher is a container management platform for companies that use containers. Rancher simplifies the process of using Kubernetes. Developers can run Kubernetes (Run Kubernetes Everywhere) anywhere, meet IT requirements and specifications, and empower DevOps teams.
rancher1.x supports docker compose, swarm, kubernates and other integrations, and the image name is rancher/server .
rancher 2.15 supports kubernates, and the mirror name is rancher/rancher .
The current stable version is 2.4.8 and the latest version is 2.5.1. It is recommended to use the stable version.
OS & Docker
TYPE | VERSION | VALIDATED/CERTIFIED ON1 |
---|---|---|
CentOS | 7.5, 7.6, 7.7, 7.8 | Docker 17.03.2, 18.06.2, 18.09.x, 19.03.x |
Oracle Linux | 7.6, 7.7 | Docker 19.03.x |
RancherOS | 1.5.6 | Docker 17.03.2, 18.06.2, 18.09.x (up to 18.09.8), 19.03.x |
RHEL | 7.5, 7.6, 7.7, 7.8 | RHEL Docker 1.13.x Docker 17.03.2, 18.06.2, 18.09.x, 19.03.x |
SLES | 12 SP5, 15 SP1 | Docker 19.03.x |
Ubuntu | 16.04, 18.04, 20.04 | Docker 17.03.2, 18.06.2, 18.09.x, 19.03.x |
Windows Server | 1809, 1903 | Docker 19.03.x EE For worker nodes only |
Rancher Kubernetes
TYPE | UPSTREAM VERSION | VALIDATED/CERTIFIED ON2,3,4,5 |
---|---|---|
Rancher Launched | 1.18.6 | etcd: v3.4.3 flannel: v0.12.0 canal: v3.13.4 nginx-ingress-controller: 0.32.0 |
Rancher Launched | 1.17.9 | etcd: v3.4.3 flannel: v0.12.0 canal: v3.13.4 nginx-ingress-controller: 0.32.0 |
Rancher Launched | 1.16.13 | etcd: v3.3.15 flannel: v0.12.0 canal: v3.13.4 nginx-ingress-controller: 0.32.0 |
Rancher Launched | 1.15.12 | etcd: v3.3.10 flannel: v0.12.0 canal: v3.13.4 nginx-ingress-controller: 0.32.0 |
This selection: CentOS 7.8, Docker 19.03.12, RKE default
Two, Rancher installation
1. Machine preparation
Machine preparation | Hardware requirements | Roles |
---|---|---|
rancher | 2C、2G | rancher/rancher:stable |
k8s-master | 4C、8G | rancher/rancher-agent:v2.4.8、Etcd、Controller Manager、Scheduler、Worker、业务service |
k8s-node | 4C、8G | rancher/rancher-agent:v2.4.8、Worker、业务service |
Note: Do not use rancher as a worker node of the k8s cluster to avoid conflicts between rancher and nginx-ingress-controller ports (both are ports 80 and 443).
2.Docker installation
**Remarks:** It is recommended to use the mirror of Netease 163 as the docker image source.
3. Rancher installation
# 设置hostname
hostname rancher && hostnamectl set-hostname rancher
mkdir -p /home/rancher/rancher
mkdir -p /home/rancher/auditlog
docker run -d --privileged --restart=unless-stopped -p 80:80 -p 443:443 -v /home/rancher/rancher:/var/lib/rancher -v /home/rancher/auditlog:/var/log/auditlog --name rancher rancher/rancher:stable
# 防火墙设置
firewall-cmd --add-port 80/tcp --permanent
firewall-cmd --add-port 443/tcp --permanent
firewall-cmd --reload
# 或者
systemctl stop firewalld && systemctl disable firewalld
Three, Web settings
Visit address: https://192.168.1.222/
Set password: admin/admin
Set language: Change English to "Simplified Chinese" in the lower right corner
Fourth, use RKE to build a K8S cluster
reference:
Rancher getting started example
note:
1. During the process of building k8s, the docker image will be automatically pulled, which is time-consuming. Depending on the network speed, it generally takes about 10 minutes .
2. If the network fails all the time, check the error log.
For example: during the process of setting up a K8S machine, I kept failing to indicate that etcd health check failed. I checked the log and found that the certificate verification failed!
Solution: Delete the test cluster and re-establish the test cluster.
# 查看日志
docker logs --since 120s etcd
Five, build the first application
Refer to "Rancher Getting Started Example".
Six, the use of Rancher cli
1. Install kubectl, Rancher cli
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install kubectl
# 支持windows、linux、MacOS
wget https://releases.rancher.com/cli2/v2.4.6/rancher-linux-amd64-v2.4.6.tar.gz
tar -zxvf rancher-linux-amd64-v2.4.6.tar.gz
mv rancher-v2.4.6/rancher /usr/bin/rancher
rm -rf rancher-v2.4.6/
2. Login authentication and testing
rancher login https://chain1/v3 --token token-m7zhb:crd5zfxvwfj4bkz66kncsml7g5z7cgsbz86bzx6hdflnwfbt2t6vk7
# 测试命令
rancher kubectl get node
Note:
If kubectl is not installed on the test machine, the following error will be prompted!
FATA[0000] kubectl is required to be set in your path to use this command. See https://kubernetes.io/docs/tasks/tools/install-kubectl/ for more info. Error: exec: "kubectl": executable file not found in $PATH
reference:
Seven, Rancher Ingress load balancing configuration
1.Rancher 2.x load balancing support
We know that Kubernetes supports Layer 4 and Layer 7 load balancing strategies. Layer 4 load balancing (or external load balancing) supports forwarding HTTP and TCP requests to Nodeports, and Layer 7 load balancing (or Ingress Controller) supports load based on Host and Path. Balance and SSL terminal, because it only supports forwarding HTTP and HTTPS requests, it needs to listen on ports 80 and 443. Please refer to the table below for the support of EKS, GKE, AKS, and RKE on each cloud platform for the 4-layer and 7-layer load balancing strategies.
Deploy the cluster | 4-layer load balancing support | Layer 7 load balancing support |
---|---|---|
Amazon EKS | AWS cloud provides support | AWS cloud provides support |
Google GKE | GCE cloud provides support | GKE cloud provides support |
Azure AKS | Azure cloud provides support | not support |
RKE on EC2 | AWS cloud provides support | Nginx Ingress Controller |
RKE is DigitalOcean | not support | Nginx Ingress Controller |
RKE on vSphere | not support | Nginx Ingress Controller |
RKE on Custom Hosts | not support | Nginx Ingress Controller |
Note: The bottom layer of RKE cluster deployment 7-layer load balancing supports Nginx Ingress Controller type by default.
2. Nginx Ingress Controller load balancing-based on Host method
# 由于未申请购买域名,临时修改hosts文件(位置C:\Windows\System32\drivers\etc\hosts)演示
# 追加以下内容
192.168.1.220 mynginx.example.com mytomcat.example.com
Note: Different domain names resolve to different applications on the same IP. (allow)
reference:
Nginx learning-use different domain names to access different projects on the same machine
3. Nginx Ingress Controller load balancing-based on Path
# 启用后端重写
nginx.ingress.kubernetes.io/rewrite-target=/
reference: