Search code examples
kubernetescassandrakubectlcoreos

How can I run the Cassandra service on a CoreOS VM with kubectl?


I am trying to create a CoreOS cluster to run Cassandra's instances. In order to do that I have been trying to install the Cassandra service only in one VM.

My Cassandra.service file is this

[Unit]
Description=cassandra 
After=docker.service 
Requires=docker.service

[Service]
Environment=CASSANDRA_CLUSTERNAME=cluster
CASSANDRA_SSL_STORAGE_PORT=7002 
EnvironmentFile=-/etc/environment
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/usr/bin/docker pull endocode/%p
ExecStartPre=/usr/bin/bash -c "echo $${COREOS_PUBLIC_IPV4:-$$(hostname - i)} | /usr/bin/etcdctl set /cassandra_%i"
ExecStartPre=/usr/bin/bash -c "while [[ ! $$(/usr/bin/etcdctl get /cassandra_1) ]]; do echo 'Waiting for Cassandra Seed node'; sleep 1; done; echo 'Cassandra Seed node is UP'; /usr/bin/etcdctl get /cassandra_1"
ExecStart=/usr/bin/bash -c "BROADCAST_ADDR=$${COREOS_PUBLIC_IPV4:- $$(hostname -i)} && CASSANDRA_SEEDS=$(/usr/bin/etcdctl get /cassandra_1 | /usr/bin/tr -d '\n') && exec /usr/bin/docker run --rm --name %p-%i
-e CASSANDRA_CLUSTERNAME=${CASSANDRA_CLUSTERNAME}
-e CASSANDRA_SEEDS=\"$CASSANDRA_SEEDS\"
-e BROADCAST_ADDR=$BROADCAST_ADDR
-e CASSANDRA_SSL_STORAGE_PORT=$CASSANDRA_SSL_STORAGE_PORT --publish 7000:7000 --publish 
$CASSANDRA_SSL_STORAGE_PORT:$CASSANDRA_SSL_STORAGE_PORT -- publish 9160:9160 --publish 9042:9042 --publish 7199:7199 endocode/%p" 
ExecStop=/usr/bin/docker stop %p-%i
ExecStopPost=/usr/bin/etcdctl rm /cassandra_%i
TimeoutStartSec=900s

[X-Fleet] 
Conflicts=%p@*.service

But to run the service I have to execute the command

fleetctl start [email protected]

and fleet has been removed from coreOS so I need to use kubernetes instead.

Which kubectl command I should use to start the Cassandra service on the VM and how can I install kubectl on CoreOS?


Solution

  • You cannot do it in such a simple way as kubectl isn't just a "new command" which replaces old fleetctl and allows you to do the same kind of things. It involves completely different approach to cluster orchestration than fleetctl which basically is a cluster manager that controls systemd at the cluster level. It combines regular systemd units with some fleet-specific properties what altogether gives you ability to run your services in the cluster. Actually it gave you such ability as it is not actively developed and it is not supported anymore for quite a long time. As you can read on CoreOS documentation they recommend transition to Kubernetes for cluster orchestration.

    Kubernetes is completely different tool and you will not be able to run with it your extended unit file as the one you attached. They were designed to be managed specifically with fleetctl (which is analogous to systemctl command which is used to manage standard systemd units).

    If it comes to your question about installing kubectl on CoreOS, it is quite straightforward and everything is explained here, however it will not help you much with your particular task. First I would recommend you to familiarize with general concepts of Kubernetes. You may start from article about running Kubernetes on CoreOS if you are using this specific system. Only after that you may look for some articles about deploying Cassandra cluster on Kubernetes like this one, available in Kubernetes official documentation but there are plenty of different tutorials on this subject and you'll find easily one that suits best to your needs.