Tag Archives: consul

Linkerd example for consul


tags: [consul, linkerd]

This post looks at how you can configure linkerd to use consul as a service discovery backend

Part of a series on linkerd:
* Part one linkerd and consul

Sample overview

The following components make up the sample system:
* curl which acts as our client application
* linkerd for proxying requests to our service
* audit example service which has a /health endpoint
* consul as our service discovery back-end
* consul-registrator
to automatically registers services with consul

System overview

+--------+      +---------+    +-----------------+
| client +----> | linkerd +--> | service (audit) |
+--------+      +----^----+    +-------+---------+
                     |                 |
                +----+---+     +-------v------------+
                | consul <-----+ consul registrator |
                +--------+     +--------------------+

1. Look up a consul service by path

The sample code for this can be found here: https://github.com/ewilde/linkerd-examples/tree/master/post-1

curl -H "Host: api.company.com" http://localhost:4140/audit/health -i

Should look up the service named audit in the consul catalog and call the service with GET /health

Linkerd configuration

namers:
- kind: io.l5d.consul
  includeTag: false
  useHealthCheck: false
routers:
- protocol: http 
  label: /http-consul
  identifier:
   kind: io.l5d.path
   segments: 1
   consume: true
  dtab: |
    /svc => /#/io.l5d.consul/dc1;
  servers:
  - port: 4140
    ip: 0.0.0.0

2. Look up a consul service by subdomain

curl -H "Host: audit.company.com" http://localhost:4140/health -i

Should look up the service named audit in the consul catalog and call the service with GET /health

Linkerd configuration

namers:
- kind: io.l5d.consul
  includeTag: false
  useHealthCheck: false

routers:
- protocol: http
  label: /host/http-consul
  identifier:
   kind: io.l5d.header.token
  dtab: |
    /consul  => /#/io.l5d.consul/dc1;
    /svc     => /$/io.buoyant.http.subdomainOfPfx/company.com/consul;
  servers:
  - port: 4140
    ip: 0.0.0.0

Written with StackEdit.

Tagged ,

Consul startup using systemd on ubuntu


tags: [consul, systemd, ubuntu]

At home I use Ubuntu, consul and (vault)[https://vaultproject.io] quite a bit, here is how I get consul to startup when my computer boots up using systemd

#!/usr/bin/env bash
set -e

echo "Installing dependencies..."
if [ -x "$(command -v apt-get)" ]; then
  sudo apt-get update -y
  sudo apt-get install -y unzip
else
  sudo yum update -y
  sudo yum install -y unzip wget
fi


echo "Fetching Consul..."
CONSUL=0.7.5
cd /tmp
wget https://releases.hashicorp.com/consul/${CONSUL}/consul_${CONSUL}_linux_amd64.zip -O consul.zip
wget https://github.com/hashicorp/consul/blob/master/terraform/shared/scripts/rhel_consul.service -O consul.service

echo "Installing Consul..."
unzip consul.zip >/dev/null
chmod +x consul
sudo mv consul /usr/local/bin/consul
sudo mkdir -p /opt/consul/data


# Write the flags to a temporary file
cat >/tmp/consul_flags << EOF
CONSUL_FLAGS="-server -bind=192.168.1.97 -ui -data-dir=/opt/consul/data -bootstrap-expect 1"
EOF

if [ -f /tmp/upstart.conf ];
then
  echo "Installing Upstart service..."
  sudo mkdir -p /etc/consul.d
  sudo mkdir -p /etc/service
  sudo chown root:root /tmp/upstart.conf
  sudo mv /tmp/upstart.conf /etc/init/consul.conf
  sudo chmod 0644 /etc/init/consul.conf
  sudo mv /tmp/consul_flags /etc/service/consul
  sudo chmod 0644 /etc/service/consul
else
  echo "Installing Systemd service..."
  sudo mkdir -p /etc/systemd/system/consul.d
  sudo chown root:root /tmp/consul.service
  sudo mv /tmp/consul.service /etc/systemd/system/consul.service
  sudo chmod 0644 /etc/systemd/system/consul.service
  sudo mv /tmp/consul_flags /etc/default/consul
  sudo chown root:root /etc/default/consul
  sudo chmod 0644 /etc/default/consul
fi

I adapted this script from https://github.com/hashicorp/consul/blob/master/terraform/shared/scripts/install.sh

Written with StackEdit.

Tagged , ,