Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Practice: Consul Mesh, Security and Operations Exercises

Test your Consul skills with exercises on intentions, ACL rules, quorum, keyring rotation and failover, with runnable checkers and worked solutions.

This final lesson of the course is a workbook. Each exercise comes with a runnable stand-in so you can check your own answer: write your solution in the editor, run it and compare. Solutions follow at the end of the page, so try each problem first. The exercises cover the second half of the course: the mesh, ACLs, multi-datacenter setups and operations.

The real product cannot run on this site; the checkers model the same rules.

How to use this page

  1. Read the problem and write down your answer.
  2. Use the editor to test it.
  3. Read the solution and compare, especially the explanation.
  4. Revisit the lesson linked next to each exercise if you missed it.

Exercise 1: intentions precedence

Intentions for destination api: * -> api deny, web -> api allow, batch -> * deny, * -> * deny. Predict the result for web -> api, batch -> api, cron -> api and batch -> db, then verify. (Lesson: Intentions.)

Python Exercise 1: predict, then run

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 2: write an ACL policy

Write a policy for a service orders that: registers itself and its sidecar, discovers any service and node, reads keys under config/orders/, and can never read config/orders/secrets/. (Lesson: ACL Rules.)

Python Exercise 2: test your rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 3: quorum arithmetic

A company runs 6 Consul servers across 2 availability zones, 3 per zone. (a) What is the quorum? (b) How many failures are tolerated? (c) What happens if one zone is lost? (d) What is a better layout? (Lesson: Raft and Quorum.)

Python Exercise 3: explore layouts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 4: rotate the gossip key

Put these steps in the correct order: keyring -remove OLD, keyring -use NEW, keyring -install NEW, keyring -list to verify. Why is the order important? (Lesson: Gossip and TLS.)

Python Exercise 4: verify your order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 5: failover design

Service api runs in dc1 (3 instances) and dc2 (3 instances), each datacenter at 70% load. If dc1 fails, what happens to dc2's load, and what would you change? Then write the service-resolver that fails over api from dc1 to dc2. (Lesson: Failover.)

Python Exercise 5: capacity math

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 6: pick a design

For each situation choose WAN federation or cluster peering, and say why: (a) one company, three regions, shared ACLs wanted; (b) two companies sharing one billing API; (c) a staging and a production cluster that must never share ACLs but where staging tests a production-exported read-only service. (Lesson: Cluster Peering.)

Solutions

Exercise 1. web -> api: allow (exact/exact beats the others). batch -> api: both * -> api deny and batch -> * deny match, and the one with the exact destination wins, also deny. cron -> api: deny. batch -> db: batch -> * and * -> *, both deny. The sample output marks any guess you got wrong.

Exercise 2. The solution above is the reference answer: exact write for the service and sidecar, broad read for discovery, a read prefix for the config and a longer deny prefix for secrets. The test list confirms it. The key insight is that the longer prefix wins over the shorter, so secrets/ is denied even though config/orders/ is readable.

Exercise 3. (a) Quorum is 4. (b) It tolerates 2 failures. (c) Losing one zone removes 3 servers, leaving 3, which is below quorum: the cluster halts writes. (d) Use three zones: (1, 1, 1) for 3 servers or (2, 2, 1) for 5. With (2, 2, 1) any single zone loss leaves at least 3 of 5 servers, which is quorum.

Exercise 4. Install, list (verify every agent has NEW), use, list (verify NEW is primary everywhere), remove. Agents must be able to decrypt the new key before anyone encrypts with it, and the old key may only go once nobody uses it.

Exercise 5. The survivor must absorb all load: 70% from each DC means 140% on dc2, so it is overloaded. Run each datacenter at 50% or below, or add a third. Resolver:

HCL
Kind = "service-resolver"
Name = "api"

Failover = {
  "*" = {
    Datacenters = ["dc2"]
  }
}

Also set a mesh gateway mode (local) in proxy-defaults and allow the callers with intentions.

Exercise 6. (a) WAN federation: one organization, replicated ACLs and config. (b) Cluster peering: separate owners, export only the billing API, each side has its own intentions. (c) Cluster peering: ACLs stay separate and the production cluster exports just the service staging needs, with an intention restricting the staging caller.

Where to go next

You have covered discovery, health, configuration, mesh, security, multi-datacenter and operations. Good next steps: run a three-server cluster in your own lab with Docker or VMs, put a small application behind sidecars, practice a restore drill and read the release notes before each upgrade. Pair it with the Docker, Terraform and system design tutorials to build and operate a complete platform.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. With 6 servers split 3 and 3 across two zones, what happens when one zone fails?

    Six servers need 4 for quorum, so losing 3 halts writes. Use three zones.
  2. 2. Which key rotation order is safe?

    Everyone must be able to read the new key before it becomes primary.
  3. 3. What is the first thing to try when a service call returns 503 in the mesh?

    A denied intention or no healthy upstream are the usual causes.
  4. 4. Why run two datacenters at 50 percent load or lower when one is the other's failover?

    Failover doubles the load on the survivor.

Summary

  • You can evaluate intentions, write least-privilege ACL policies, reason about quorum and failure zones, rotate keys safely and design failover.
  • Choose federation inside one organization and peering across ownership boundaries.
  • Practice with real clusters: drills on restores, upgrades and failures build the confidence that documentation cannot.

Next: back to the Consul tutorial