Welcome to part 3 of the DC/OS 101 Tutorial
You now have a working persistence layer - Redis - running in your cluster. In this section you will deploy a simple app connecting to Redis.
Let us first take a short look at the app. It is very simple and just checks whether it can reach Redis and then prints the total number of keys stored there.
import os import redis import time print("Running on node '"+ os.getenv("HOST") + "' and port '" + os.getenv("PORT0")) r = redis.StrictRedis(host='redis.marathon.l4lb.thisdcos.directory', port=6379, db=0) if r.ping(): print("Redis Connected. Total number of keys:", len(r.keys())) else: print("Could not connect to redis") time.sleep(5)
The Python script has a dependency on the redis-py Python library, which you cannot assume to be present on all agent nodes. Because of this, you should run it in the
mesosphere/dcos-101Docker container that provides all of the dependencies. Feel free to take a look at the DOCKERFILE, which was used to create the
Have a look at the app definition. The app definition is the configuration which Marathon will use to deploy and manage the application. This app definition will download the python script and then run it inside the
app1to Marathon using the app definition:
dcos marathon app add https://raw.githubusercontent.com/joerg84/dcos-101/master/app1/app1.json
By looking at all DC/OS tasks:
Here you should look at the state this task is currently in, which probably is either
By looking at all Marathon apps:
dcos marathon app list
By checking the logs:
dcos task log app1
Here you should see which node and port
app1is running on, and the output from the app showing the number of keys in Redis. The node and ports might vary between different runs and even during the lifetime of the app, depending on events in the cluster.
- You have deployed your first app inside a Docker container using Marathon.
- You have verified that the app is running and successfully connected to the previously deployed Redis service.
You have just deployed your first app using Marathon directly. Also note that the Redis service itself is running via Marathon.
Marathon is referred to as the init system of DC/OS, as its main job is to support long running services. Marathon also allows for scaling or uninstalling of applications. There are multiple options to deploy and maintain apps on Marathon besides the DC/OS GUI:
- DC/OS CLI: You have just used this option to deploy your app. To get more information on the marathon CLI use
dcos marathon app --help.
- HTTP endpoints: Marathon also comes with an extensive REST API
In the next section, you will learn about DC/OS service discovery by exploring the different options available for apps in DC/OS.