Deploying Docker’s Voting App in Okteto

This guide will show you how simple it is to deploy a complex application (Docker’s voting app) with okteto.

At a high level, this guide will show you how to:

  1. Create an okteto manifest for each service of the voting-app.
  2. Deploy your service manifests in okteto.
  3. Browse the okteto service view.
  4. Destroy the okteto services created in the previous steps.

This guide assumes that you already have a project configured. If you haven’t, we recommend you first review our project’s guide.

Deploy the Voting App

The voting app is defined as a stack of six microservices:

  • redis: In-memory k/v store that collects votes
  • worker: Stores votes in the database
  • db: Persistent store for votes
  • result: Web server that pulls and displays results from the database
  • vote: Web front-end that displays voting options
  • lb: Container-based load balancer

To deploy the voting app in okteto, you need to convert each service to an okteto service manifest.
Once you have every service converted, you can start to deploy and test them one by one.

DB

Let’s start by deploying the db service in okteto:

  1. Click on the ‘+ Add Service’ icon on the top left to create a new service.

  2. On the Manifest section, paste the manifest of the db service:

1
2
3
4
5
6
7
name: db
stateful: true
containers:
db:
image: postgres:9.4
ports:
- tcp:5432:tcp:5432

After a few minutes, the db service will be deployed (green) and a new section Endpoints section will appear with the URL you can use to access your service. Because the service is not marked as public, this endpoint won’t be publicly accessible. The rest of the services on the same okteto project will resolve db to this service endpoint.

As the service is deployed, its logs will appear in the History section below the service manifest. Every action you perform via okteto will be displayed as part of the service’s history.

db service

Redis

Repeat the same steps as before, but paste the redis manifest:

1
2
3
4
5
6
7
name: redis
stateful: true
containers:
redis:
image: redis:alpine
ports:
- tcp:6379:tcp:6379

As you can see, the redis service has a similar definition than the db service but exposing a different port and using a different container image.

Worker

Repeat the same steps as before, but paste the worker manifest:

1
2
3
4
name: worker
containers:
worker:
image: docker/example-voting-app-worker:latest

The worker service is also private, but it does not expose any port to the rest of the services in the okteto project.

Result

Repeat the same steps as before, but paste the result manifest:

1
2
3
4
5
6
7
name: result
public: true
containers:
result:
image: docker/example-voting-app-result:latest
ports:
- http:80:http:80

Note that the result service is public. For public services, okteto creates a publicly accessible endpoint, which can be used to access it from your browser, for example. This endpoint is shown in the Endpoints section of the service view. The endpoint is created as a subdomain of okteto.net using your service and project names.

Browse to the endpoint shown in the UI to validate that the service is running properly.

Vote

Repeat the same steps as before, but paste the vote manifest:

1
2
3
4
5
6
7
8
name: vote
replicas: 3
public: true
containers:
vote:
image: docker/example-voting-app-vote:latest
ports:
- http:80:http:80

Note that the vote service has 3 replicas. For this case, okteto will deploy a load balancer on port 80 in front of the vote containers and will ensure that there are always 3 containers online and healthy. If a container is destroyed or is deemed unhealthy, okteto will automatically relaunch it for you.

Browse to the vote endpoint shown in the UI to validate that the service is running properly.

At this point, you have a fully functional voting app. Try it out by voting a few times between cats and dogs using the vote service’s endpoint, and then see the results using the result service’s endpoint.

Destroy your Okteto Services.

To destroy the created services, click the Destroy button on the top right corner of each service. This will stop and delete all the resources created when deploying the service. Once the service is destroyed, you will have access to its history and logs for one hour. After that, it won’t be accessible via okteto anymore.

More information: