This blog is written at Jan 2019. And the k8s and ceph-helm version used are:
- k8s: v1.12.2
- ceph chart: 743a7441ba4361866a6e017b4f8fa5c15e34e640, which is the head of the master branch of ceph-helm.
What is ceph
In a simple term:
-
Ceph is a opensource software storage platform. The core members of ceph have included Canonical, Cisco, Red Hat, Intel e.g.
-
Ceph implements object storage and provides object-, block- and file-level storage
Why helm
Helm is a package management tool for kubernetes. There are basically two parts for Helm, the helm client and tiller. According to its documentation, Helm is very easy to install to a k8s cluster:
Install Ceph by Helm
1. Build the ceph-chart
Checking out and building the ceph helm chart is the very first thing the offical tutorial introduced. By reading this issue on the offical ceph helm chart repo, the ceph-helm in official helm repo is very outdated.
Once above done, the helm will use the local helm chart to install ceph into your k8s.
2. Install Ceph Cluster into K8s
Below is a typical ceph config file for k8s:
Make sure the public and cluster IP are same and covered by the actual host’s IP range. Otherwise, the ceph network will not function well.
The osd_devices
part is used to define the physical hard drive that will be used as the storage device. You must make sure that the hard drive is clean and not contain any partition. Otherwise, you can use the following command to checkout and delete those partitions:
You will need run this every time you reinstall ceph cluster and want ceph to use that hard drive as its storage again.
After you’ve created the ceph chart, you might have an unhealthy cluster instead of a healthy one in the offical tutorial. Don’t worry about this, if it’s just unhealthy caused by unactive pgs. for example my one:
3. Configure the keys for a pod to use PVC
Now we need configure the keys for a pod in a namespace so that it can use the persistent volume claim.
4. Adjust the Ceph Pool size
It’s almost impossible to have a healthy ceph cluster after first installation. Now, let’s fix this. First, create a rbd pool:
From what I’ve noticed, the ceph status depends on the osd size and pool size. My ceph cluster has configured two osd at the very beginning but relatively large pool size. And I’ve tried several times, none of those tries have successful ceph cluster. The main reason is the default pool size isn’t proper for a small osd cluster. To adjust the pool size:
For my cluster, I simply reduce all the pool size to 1 since I only have 2 osd devices. Afterwards, the ceph cluster status should turn to health.
5. Install Ceph client on host machine
Installing ceph client into the host machine is missing in all the tutorials about installing ceph by Helm. This is because rbd will be used when Kubelet creates and mounts the pvc to the pod. If you you didn’t install ceph client, you may see the following errors or similar and the pod will be stucked at Container Creating stage:
rbd: Error creating rbd image: executable file not found in $PATH
There is no extra configuration needed to be done after installing rbd or ceph-client.
Install ceph-common
package on to your host machine which has the ceph-mon and ceph-mgr running is all you need.
6. Test the Ceph cluster
In order to tell if the ceph cluster is working or not, we can create a pvc and mount it to a pod:
Now, the pvc and its pv should be created. Use kubectl get pvc
and kubectl get pv
to see the the pvc and the pv.
Next, we want to create a pod use that pvc we just created:
7. Managing Kubernetes and its network
By the time you create the pod, you may see the container is stucked at conatiner creating stage. And the log could say something like:
can not resolve ceph-mon.ceph.svc.cluster.local
Remember we’ve installed the ceph onto the host machine and the rbd on host will be invoked by kubelet during pod creation. The host machine is trying to reach the ceph monitor node and failed since it’s actually in the k8s cluster to use the kube-dns. There are few ways to fix this. One is add the kube-dns svc endpoint to /etc/resolv.conf
as a dns service. Or add the domain mapping to the /etc/hosts
to my node’s host machine.
11.7.100.123 ceph-mon.ceph.svc.cluster.local
However, the second way is not secure as if the ceph-mon is restart or the IP is changed inside k8s cluster. The ceph cluster will be broke.
After fixing the dns issue, the cannot resolve ceph-mon.ceph.svc.cluster.local
should be gone. But I see another one which is:
timeout expired waiting for volumes to attach/mount for pod :
Error syncing pod 096ac42b-919a-11e8-bd1d-fa163eaae838
("mypod_ceph(096ac42b-919a-11e8-bd1d-fa163eaae838)"), skipping:
timeout expired waiting for volumes to attach/mount for pod
"ceph"/"mypod". list of unattached/unmounted volumes=[vol1]
The offical tutorial has documented the reason, which is:
Kubernetes uses the RBD kernel module to map RBDs to hosts.
Luminous requires CRUSH_TUNABLES 5 (Jewel). The minimal kernel
version for these tunables is 4.5. If your kernel does not
support these tunables, run ceph osd crush tunables hammer
So bash into your ceph-mon pod and run ceph osd crush tunables hammer
. It’s caused by the ceph helm chart is using a old version of luminous image.
Conclusion
Above is all you need to do for using helm install ceph.
Delete Ceph cluster
Delete ceph with helm will open another worm can. When you run helm delete --purge ceph
, two extra one-time pod will be started to delete all keys that ceph created. However, if you run find / -name "*ceph*"
, you will see there are some leftover that the helm didn’t managed well:
...
/var/lib/ceph-helm
/var/lib/ceph-helm/ceph
/var/lib/ceph-helm/ceph/mon/bootstrap-osd/ceph.keyring
/var/lib/ceph-helm/ceph/mon/bootstrap-mds/ceph.keyring
/var/lib/ceph-helm/ceph/mon/bootstrap-rgw/ceph.keyring
...
Those keys will be a blocker for your brand new ceph cluster trying to communicate to each other. So we have delete them manually everytime if we want to re-install ceph by helm.
Also, you may need remove the partition listed in step 2 when a harddrive is reused.
Reference
- Ceph at Wikipedia
- Installation (Kubernetes + Helm)
- Installing Helm
- 跟我学 K8S–运维: helm 安装 ceph 到 kubernetes 集群
- ceph-helm