Rancher and k8s 2019(3)Clean Installation on CentOS7

阅读更多
Rancher and k8s 2019(3)Clean Installation on CentOS7

Set Up 3 machines
192.168.56.110     rancher-home
192.168.56.111     rancher-worker1
192.168.56.112     rancher-worker2

Set Up rancher-home
The network config
Go to the network setting directory
> cd /etc/sysconfig/network-scripts/

Open the configuration file, change the last line as follow:
> sudo vi ifcfg-enp0s3
ONBOOT=yes

Enable the second network adapter on VirtualBox, copy and set the configuration file for the second network
> sudo cp ifcfg-enp0s3 ifcfg-enp0s8

> cat ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.110
NETMASK=255.255.255.0
DEFROUTE=yes

Update the latest software
> sudo yum update

Disable firewall
> sudo systemctl stop firewalld.service
> sudo systemctl disable firewalld.service

Install Docker
> sudo yum install -y yum-utils device-mapper-persistent-data lvm2
> sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Then the install command will work
> sudo yum install docker-ce
> sudo usermod -aG docker $(whoami)
> sudo systemctl enable docker.service
> sudo systemctl start docker.service

Start the Rancker from Docker Image
> mkdir -p ~/tool/rancher-docker
> sudo ln -s /home/carl/tool/rancher-docker /opt/rancher-docker
> sudo ln -s /opt/rancher-docker /opt/rancher

Go to the working directory
> cd /opt/rancher
> mkdir /opt/rancher/rancher_home

Prepare a Makefile there
> cat Makefile
PORT=9090
SSL_PORT=9091
IMAGE=rancher/rancher
TAG=stable
NAME=rancher-$(PORT)
run:
docker run \
-d \
        --restart=unless-stopped \
-p $(PORT):80 \
-p $(SSL_PORT):443 \
-v $(shell pwd)/rancher_home:/var/lib/rancher/ \
--name $(NAME) \
$(IMAGE):$(TAG)
clean:
docker stop ${NAME}
docker rm ${NAME}

Start Rancher on the first server
> make run PORT=80 SSL_PORT=443

Visit the URL
https://192.168.56.110/g/clusters

It will ask us to update the password. Then we can create a customer cluster via k8s.
For the home machine, do not use it as worker
>   sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.8 --server https://192.168.56.110 --token 5x6452wfj86kpmxkzwxhjt7mpsbx5hxx7p66jqnpvdqk469mrxh4v7 --ca-checksum 326354803f20bff6574e64d735e854fe73e8d7fd5e9ff6a13d8252fbf5deeefa --node-name rancher-home --address 192.168.56.110 --internal-address 192.168.56.110 --etcd --controlplane

Set Up rancher-worker1
The network config
Go to the network setting directory
> cd /etc/sysconfig/network-scripts/

Open the configuration file, change the last line as follow:
> sudo vi ifcfg-enp0s3
ONBOOT=yes

Enable the second network adapter on VirtualBox, copy and set the configuration file for the second network
> sudo cp ifcfg-enp0s3 ifcfg-enp0s8

> cat ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.111
NETMASK=255.255.255.0
DEFROUTE=yes

Update the latest software
> sudo yum update

Disable firewall
> sudo systemctl stop firewalld.service
> sudo systemctl disable firewalld.service

Install Docker
> sudo yum install -y yum-utils device-mapper-persistent-data lvm2
> sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Then the install command will work
> sudo yum install docker-ce
> sudo usermod -aG docker $(whoami)
> sudo systemctl enable docker.service
> sudo systemctl start docker.service

On the rancher-worker1
>   sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.8 --server https://192.168.56.110 --token 5x6452wfj86kpmxkzwxhjt7mpsbx5hxx7p66jqnpvdqk469mrxh4v7 --ca-checksum 326354803f20bff6574e64d735e854fe73e8d7fd5e9ff6a13d8252fbf5deeefa --node-name rancher-worker1 --address 192.168.56.111 --internal-address 192.168.56.111 --worker


If I need, here is the command to kill all the containers at one
> docker kill $(docker ps -q)

Remove all the unused containers and images
> docker system prune

After I start the cluster, I can add a nginx web server there

Visit the worker page, it works pretty well.
http://rancher-worker1:31489/

After everything is working fine, we can do the similar step to set up rancher-worker2 to join the cluster as worker.

Set Up rancher-worker2

The network config
Go to the network setting directory
> cd /etc/sysconfig/network-scripts/

Open the configuration file, change the last line as follow:
> sudo vi ifcfg-enp0s3
ONBOOT=yes

Enable the second network adapter on VirtualBox, copy and set the configuration file for the second network
> sudo cp ifcfg-enp0s3 ifcfg-enp0s8

> cat ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.111
NETMASK=255.255.255.0
DEFROUTE=yes

Update the latest software
> sudo yum update

Disable firewall
> sudo systemctl stop firewalld.service
> sudo systemctl disable firewalld.service

Install Docker
> sudo yum install -y yum-utils device-mapper-persistent-data lvm2
> sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Then the install command will work
> sudo yum install docker-ce
> sudo usermod -aG docker $(whoami)
> sudo systemctl enable docker.service
> sudo systemctl start docker.service

On the rancher-worker1
>   sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.8 --server https://192.168.56.110 --token 5x6452wfj86kpmxkzwxhjt7mpsbx5hxx7p66jqnpvdqk469mrxh4v7 --ca-checksum 326354803f20bff6574e64d735e854fe73e8d7fd5e9ff6a13d8252fbf5deeefa --node-name rancher-worker2 --address 192.168.56.112 --internal-address 192.168.56.112 --worker


References:
https://gist.github.com/evanscottgray/8571828

你可能感兴趣的:(Rancher and k8s 2019(3)Clean Installation on CentOS7)