Tutorials

Hello Dotmesh on Kubernetes

Getting Started with Dotmesh on Kubernetes

You're gonna need.

Clone the app

The moby counter app is a very basic drawing app: it allows you to click to put logos on the screen. The location of the logos is persisted to a Redis database.

First, clone the app repo from gihub.


git clone https://github.com/dotmesh-io/moby-counter
cd moby-counter

The kubernetes yamls in kubernetes/ includes not only the app but also a PVC which includes a request for a dotmesh datadot.

Start the app.


cd kubernetes
kubectl apply -f .

You should see that the datadot referenced in the redis-pvc.yaml file has been created.


dm list

Make moby_counter the current datadot.


dm switch moby_counter

This means that later dm commands will operate on that datadot, as indicated by the * in the list.


dm list
  VOLUME       BRANCH  SERVER   CONTAINERS  SIZE       COMMITS  DIRTY
* moby_counter master  8f15abe  /moby       19.00 kiB  1        9.50 kiB

Capture the empty state

Now, let’s capture the empty state, run:


dm commit -m "Empty state"

Now, load up the app in your browser at http://<ip-of-a-cluster-node>:30004/ You should have the address of a cluster node in the output of dm remote -v.

NOTE - you may need to open port 30004 on any firewall in front of your Kubernetes cluster. If you followed our GKE tutorial then we already did that.

You’ll see an invitation to click on the screen. Before you do, let’s make a new branch:


dm checkout -b branch_a

Switch branches manually

The dotmesh Kubernetes integration doesn’t automatically stop and start containers when you switch branches with dm checkout like the Docker integration does.

Instead, the branch is pinned in the redis-pvc.yaml file using moby_counter@master syntax, which means “pin this mount of this dot to this branch”.

So, in order to switch branches in the app as well, we’ll need to change and re-apply the Kubernetes YAML.


sed -i '' 's/master/branch_a/' redis-pvc.yaml
kubectl delete -f . && kubectl apply -f .

Draw an A on the screen

Now, draw an “A” on the screen! Then capture it:


dm commit -m "A on the screen"

Note that if you go back to the master branch, the app updates automatically and you go back to your empty state:


dm checkout master
sed -i '' 's/branch_a/master/' redis-pvc.yaml
kubectl delete -f . && kubectl apply -f .

Let’s go back to the A state, as next we’ll push it to the dothub.


dm checkout master
sed -i '' 's/master/branch_a/' redis-pvc.yaml
kubectl delete -f . && kubectl apply -f .

Push “A state” to the dothub

At this point, try pushing your branch to Dothub.

Start by registering for an account by clicking the link above.

Then back here, we’ll set an environment variable with your Dothub username in it:

export HUB_USERNAME=<username>

Then add the hub as a remote:


dm remote add hub ${HUB_USERNAME}@dothub.com

You will be prompted for your API key, which you can get from the Settings/API Key page.

You can then push branches to the hub.


dm push hub moby_counter branch_a

Then, go to Dothub and you should be able to see the volume, its branches and commits.

Optional: Adding a collaborator

Prove that data can move between Kubernetes clusters by inviting a friend or co-worker to join the Dothub too!

When they’ve signed up, add them as a collaborator, by going to the Settings page for your datadot, and type their user’s username to add them as a collaborator.

Finally, send them a link to the following section so that they can clone your datadot and then you can finish the tutorial together!

Instructions for your co-worker

So you been invited to pull down someone else’s datadot on Kubernetes? Great, let’s do it! First, sign up for an account on the Dothub.

Then tell the person who sent you here to add you as a collaborator to their dot.

Next, let’s set up some environment variables.

export DOT_OWNER=<their-username>
export COLLABORATOR=<your-username>
You're gonna need.

Authenticate to the hub:


dm remote add hub ${COLLABORATOR}@dothub.com

You will be prompted for your API key, which you can get from the Settings/API Key page.

Clone the repo locally


git clone https://github.com/datamesh-io/moby-counter
cd moby-counter

Clone and switch to the dot before you start the app:


dm clone hub ${DOT_OWNER}/moby_counter

Make moby_counter the current datadot.


dm switch moby_counter

This means that later dm commands will operate on that datadot, as indicated by the * in the list.


dm list

Pull and checkout the branch your co-worker created earlier:


dm pull hub moby_counter branch_a
dm checkout branch_a

Start the app in your Kubernetes cluster:


cd kubernetes
sed -i '' 's/master/branch_a/' redis-pvc.yaml
kubectl apply -f .

Now navigate to http://<ip-of-a-cluster-node>:30004/ and you should see the same data that your coworker created running on your Kubernetes cluster!

What’s next?

Try a more advanced version of the app with multiple microservices and polyglot persistence, and start building up a set of interesting states for your team in: