How to set up your own Rancher environment

Share

Well first of all you need some nodes, nodes that will be used as a platform for your docker services but we won’t cover the node installation only the configuration and the rancher part.
I used 5 Coreos virtual machines as my nodes, with a NFS mapped partition for persistent data. I also have to mention that my rancher server runs on a different Coreos virtual machine (yes, I have 6 vms).
To install Coreos you need to make a cloud-init config, this config will have all your machine’s details. For example, my config looks something like this, with obvious changes:

#cloud-config

hostname: rancher-node1

coreos:
  units:
    - name: 00-eth0.network
      runtime: true
      content: |
        [Match]
        Name=eth0

        [Network]
        Address=192.168.x.x/24
        Gateway=192.168.x.y
        DNS=8.8.8.8

    - name: docker-tcp.socket
      command: start
      enable: true
      content: |
        [Unit]
        Description=Docker Socket for the API

        [Socket]
        ListenStream=2375
        BindIPv6Only=both
        Service=docker.service

        [Install]
        WantedBy=sockets.target
    - name: docker.service
      drop-ins:
        - name: 50-insecure-registry.conf
          content: |
            [Service]
            Environment='DOCKER_OPTS=--insecure registry="10.10.0.0/16"'
    - name: rpc-statd.service
      command: start
      enable: true
    - name: var-lib-registry.mount
      command: start
      content: |
        [Mount]
        What=192.168.x.z:/srv/docker/registry
        Where=/var/lib/registry
        Type=nfs
  update:
    reboot-strategy: etcd-lock

write_files:
  - path: "/etc/resolv.conf"
    permissions: "0644"
    owner: "root"
    content: |
      nameserver 8.8.8.8

To install the Coreos operating system with this config you have to know which is your base hard-drive (sda, vda) and then run this command:

coreos-install -d /dev/sda -C stable -c cloud-init

Let’s break that command apart, so -d refers to your hard-drive (you can easily find out which is your hard drive by typing the command sudo fdisk -l). After that comes the -C parameter, this is the os version, there are 3 Coreos versions: stable, beta and alpha. And the last one is the cloud config mentioned earlier, you just have to make a random file, with a random name (i used cloud-init), add the code and mention it in the command (-c cloud-init).

So, let’s get started. As I mentioned earlier I have a mapped partition located on /var/lib/registry. This is important because this way I can make backups to my rancher’s mysql database and I won’t lose data (also it’s on my NFS server, not on my vm).
The NFS mounting part in the cloud-init config looks like this:

- name: var-lib-registry.mount
      command: start
      content: |
        [Mount]
        What=192.168.x.z:/srv/docker/registry
        Where=/var/lib/registry
        Type=nfs

Where 192.168.x.z is the NFS server.

The command to run a rancher container looks like this:

docker run -d --restart=unless-stopped -p 8080:8080 -p 9345:9345 rancher/server

But as I was saying I modified it to use a volume, so mine looks like this:

docker run -d --restart=unless-stopped -p 8080:8080 -p 9345:9345 -v /var/lib/registry/rancher/var/lib/mysql:/var/lib/mysql rancher/server

I recommend using the built-in mysql server because if you use a separate mysql container the system might fail.
If the system starts correctly you should access in a browser the IP of the Coreos machine like this: https://x.x.x.x:8080, where x.x.x.x is your machine’s IP address. After which you will be notified that the connection isn’t safe.

1

Accept the risk and access the website.

accept the risk

This is how it should look like:
Welcome to Rancher

The next step describes how to configure authentication. You have to click the Admin tab, then click on Access Control. Here you have multiple ways to configure authentication but we will use Local Authentication.

Configure authentication

You just have to enter a Login username and a password (twice).

login

Then click on Enable Local Auth.

Enable local auth

By now you realized that rancher is screaming that you don’t have nodes configured, so let’s do that. Click on the infrastructure Tab and an Add Host button appears.
nodes configure

Click it and the documentation to add a host appears.

8

A screen will appear asking for your URL, you should set it to http://x.x.x.x:8080, not https because it might fail.

9

Don’t get scared, if you already started your Coreos machines you just have to copy the script at number 5 and paste it in the Coreos machine console (all the machines except the one with the rancher container).

10

Hit close and one by one the nodes appear.

11

You are almost done, click on the Stacks tab to add your services (custom built or from the Catalog).

12

These are services, not containers, every stack has at least one service and every service has at least one container.
Be aware that after you add your first node it will take some time until rancher’s internal services will be up and running. So wait 5 minutes before you add your services.

As an example I will show you how to configure a Zookeeper/Kafka service, for now just click on the Browse Catalog button.

13

First you should set up zookeeper, so click on the View Details button.

14

A bunch of configurations will appear, but we will configure a basic one, so you just have to click on Launch.
After which you should add Kafka, repeat the steps mentioned earlier and click on Kafka’s View Details button. The most important part here is to set you Zookeeper. Click on the Choose a Service tab, and select your Zookeeper from the services list, like in the image below.

15

Click on launch and your service will be added automatically. And you’re done, when everything is started it should look like this:

16

The image above is the Stack/All tab, here you will see your services and rancher’s internal services.

So this is it, feel free to ask questions in the comment area down below.

Tags:

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close