Everything is containerized, so Gluster . As you know, Gluster Container images are available for long time ( for both CentOS and Fedora ) in Docker hub. In previous blog posts, we saw how to build/run Gluster Containers. In this setup, we will try to set up a Kubernetes cluster with Gluster containers. If you dont know much about kubernetes , please go through this . In short, kubernetes is an orchestration software for container environment which brings the services like scheduling, service discovery..etc. We will deploy a kubernetes cluster in couple of atomic nodes. Then run Gluster containers on these atomic hosts via kubernetes. Once the gluster containers are running, we will form a trusted pool out of these gluster containers and export a volume, so that other application containers can make use of this volume to store its data in a persistent way!!.
Sounds interesting ? Yes, let us start.
NOTE: This article also discuss the steps to configure etcd server ( a key value store).. For this particular setup we may not need to configure etcd. However your environment may need, for example to configure flannel.
Setup
Three centos ( You can also use fedora/RHEL) atomic hosts :
To configure/install CentOS atomic hosts, please follow the steps mentioned here.
and the atomic images can be downloaded from here
Then start the atomic installation, if cloud init is configured, it will come into play and ask for “atomic host” login.
Note: The above is based on the cloud-init configuration. If you have customized the cloud-init configuration for different username and password, please supply the same. (wait till the vm to completely load meta-data and user-data. else it will throw invalid login till its completely loaded)
At this stage we have three atomic hosts.:
If you already have this setup, make sure all the machines are able to talk to each other.
First things first,
Upgrade your system to latest docker, etcd, kubernetes..etc, in all nodes.
With the three systems in place, the next thing is to set up Kubernetes. Setting up Kubernetes on the Master, select any system to be master.
1. Etcd configuration:
Edit the /etc/etcd/etcd.conf. The etcd service needs to be configured to listen on all interfaces to ports 2380. (ETCD_LISTEN_PEER_URLS) and port 2379 (ETCD_LISTEN_CLIENT_URLS), and listen on 2380 on localhost (ETCD_LISTEN_PEER_URLS)
2. Kubernetes Configuration:
Edit the /etc/kubernetes/config file and change the KUBE_MASTER line to identify the location of your master server (it points to 127.0.0.1, by default). Leave other settings as they are.
3. Kubernetes apiserver Configuration:
Edit the /etc/kubernetes/apiserver and add a new KUBE_ETCD_SERVERS line (as shown below), then review and change other lines in the apiserver configuration file. Change KUBE_API_ADDRESS to listen on all network addresses(0.0.0.0), instead of just localhost. Set an address range for the KUBE_SERVICE_ADDRESS that Kubernetes can use to assign to services (see a description of this address below). Finally, remove the term “ServiceAccount” from the KUBE_ADMISSION_CONTROL instruction.
4. Start master services:
To run the Kubernetes master services, you need to enable and start several systemd services. From the master, run the following for loop to start and enable Kubernetes systemd services on the master:
5. Setting up Kubernetes on the Nodes
On each of the two Kubernetes nodes, you need to edit several configuration files and start and enable several Kubernetes systemd services:
1.Edit /etc/kubernetes/config:
Edit the KUBE_MASTER line in this file to identify the location of your master (it is 127.0.0.1, by default). allow_privileged must be set to true. Leave other settings as they are.
2.Edit /etc/kubernetes/kubelet:
In this file on each node, modify KUBELET_ADDRESS (0.0.0.0 to listen on all network interfaces), KUBELET_HOSTNAME (replace hostname_override with the hostname or IP address of the local system). You may leave this blank to use the actual hostname, set KUBELET_ARGS, and KUBELET_API_SERVER as below. --host-network-sources=* is specified to use the host networking option of docker(–net=host). You can use any networking mode of docker. However in this setup, we use --net=host option to make sure we get maximum performance.
3. Edit /etc/kubernetes/proxy:
No settings are required in this file. If you have set
KUBE_PROXY_ARGS, you can comment it out:
4. Start the Kubernetes nodes systemd services:
On each node, you need to start several services associated with a Kubernetes node:
5. Check the services:
Run the netstat command on each of the three systems to check which ports the services are running on. The etcd service should only be running on the master.
From master:
From nodes:
6. Test the etcd service:
Use the curl command from any of the three systems to check that the etcd service is running and accessible: use the master node IP or hostname, run on all nodes.
7.Check the nodes and its status:
From the master,
Pay attention to the status field of above command, it should be in ready status to run any containers to run. At this stage, we can say you have a working kubernetes cluster.
Cool, Isnt it ?
Few things to do before we start our containers.
GlusterFS peers will need access to local storage that can be used as the GlusterFS peer’s brick. We have to create a mount point, for example: /mnt/brick1 in nodes where we want to run the gluster containers. To specify the node where to run the containers in Kubernetes, we have to mention NodeSelector label to ensure that it is always scheduled on a specific node. As you know the container pod definition file will have these mentioned in it. Run the below command for your nodes to work with the yaml file configuration.
It sets the node names as a label to the nodes( in below command, key is name and value is worker-1). atomic-node1 is hostname of my system please use your respective name of the node.
atomic-node1 is my node1
atomic-node2 is my node2
In master:
Copy these yaml file: The sample yaml files are available here
bash-4.2# cat gluster-2.yaml apiVersion: v1 kind: Pod metadata: name: gluster-2 labels: name: gluster-2 spec: hostNetwork: true nodeSelector: name: worker-2 containers: – name: glusterfs image: gluster/gluster-centos ports: – name: web containerPort: 80 volumeMounts: – name: brickpath mountPath: “/mnt/brick1” securityContext: capabilities: {} privileged: true volumes: – name: brickpath hostPath: path: “/mnt/brick1”
Now that you have the yaml files which specifies the pods structure. If you don’t know what is pod in Kubernetes, please refer this url.
Finally it is the time for us to create Gluster containers!
In master:
-bash-4.2# kubectl create -f gluster-2.yaml pods/gluster-2
Awesome ! gluster containers started in kubernetes nodes. Lets verify its status by running below command.
So the containers are started Successfully, let’s check on the nodes.
Go to Node1:
Go to Node2:
So we have two containers running in different atomic hosts, to form a trusted pool, these containers have to be peer probed. From one container we are going to peer probe to another container, since we are using host configuration ( –net=host option in docker run enabled via kubernetes configuration ) give the centos atomic host’s IP to peer probe. If you are using some other SDN ( for ex: flannel) use the containers IP to peer probe.
Hostname: 10.70.43.88 Uuid: 1a76df91-4e8f-4d4c-87b8-6254e3337c6d State: Peer in Cluster (Connected)
Now that we have the Trusted storage pool with node1 and node2, We shall create a volume in the container.
Task Status of Volume newvol —————————————————————————— There are no active volume tasks
Great, we have our volume exported from the trusted pool formed between the gluster containers. Now that we have our volume running , lets mount our volume to the master node. As shown above in the picture, this volume can be mounted in any of the system, it can be a micro service or application container or atomic host or some other bare metal system. The only requirement is that the gluster server should be reachable from the mount client system. For ex: if there is a application container runnning in your cluster, you can mount the gluster volume inside it and use it for storing data.
In this setup, we are mounting it inside the kubernetes master node.
In Master,
So We have mounted the volume!!
In this article, we have created a Kubernetes cluster on atomic hosts and ran Gluster Containers and created a trusted storage pool out of these containers, then created and exported a volume successfully for the client to use it as a persistent data store.
PS# If you any queries/comments please leave a comment.
Authors: Mohammed Ashiq and Humble Chirammal