SlideShare ist ein Scribd-Unternehmen logo
1 von 196
Downloaden Sie, um offline zu lesen
Smart Networking with Service Meshes
aka What is this “Service Mesh” hype about?
Developer Advocate, HashiCorp
@anubhavm
Anubhav Mishra
@anubhavm
Anubhav Mishra
Developer Advocate, HashiCorp
@anubhavm
Anubhav Mishra
Developer Advocate, HashiCorp
Atlan&s
@anubhavm
Anubhav Mishra
Developer Advocate, HashiCorp
Atlan&s
@anubhavm
Anubhav Mishra
Developer Advocate, HashiCorp
Atlan&s
Gopher Artwork by Ashley McNamara
@anubhavm
Anubhav Mishra
Developer Advocate, HashiCorp
Atlan&s
Gopher Artwork by Ashley McNamara
PROVISION, SECURE AND RUN ANY INFRASTRUCTURE
Nomad Consul
Vault
Vagrant Packer Terraform
Consul Enterprise
Terraform Enterprise
Vault Enterprise
PRODUCT SUITEOSS TOOL SUITE
RUN
Applications
SECURE
Application Infrastructure
PROVISION
Infrastructure
FOR INDIVIDUALS FOR TEAMS
Nomad Enterprise
@anubhavmBlog Post Link: https://www.hashicorp.com/blog/smart-networking-with-consul-and-service-meshes
Agenda
@anubhavm
Agenda
1. Introduction to “Smart Networking” and “Service Mesh”
2. Introduction to HashiCorp Consul
3. Architecture and overview of Consul
4. Exercises (Hands-On Lab)
• Exploring Service Discovery, K/V Store, and Consul Template
• NGINX and Consul (Smart Proxy)
• Fabio and Consul (Smart Networking in containers)
• Consul Connect (Service Mesh)
• Consul Connect for Service to Service Communication
• Consul Connect for Service to Database Communication
• Consul Connect for Serverless Applications
5. Conclusion
6. Discussion / Q&A
“Smart Networking”
@anubhavm
Service
A
Service
B
@anubhavm
Service
A
Service
B
Service
B
Service
B
Multiple Instances?
@anubhavm
Service
A
Service
B
Service
B
Service
B
Multiple Instances?
Service Discovery
@anubhavm
Service
A
Service
B
@anubhavm
Service
A
Service
B
Request Failed
@anubhavm
Service
A
Service
B
Request Failed
Retries
@anubhavm
Service
A
Service
B
@anubhavm
Service
A
Service
B
Cert: serviceA.foo.com Cert: serviceB.foo.com
Assigning Identity
@anubhavm
Service
A
Service
B
Cert: serviceA.foo.com Cert: serviceB.foo.com
Assigning IdentityMutual TLS
@anubhavm
Service
A
Service
B
Cert: serviceA.foo.com Cert: serviceB.foo.com
Authorizing trafficMutual TLS
Allow?
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
Service
A
Service
B
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
Service
A
Service
B
Ribbon
@anubhavm
Dumb Pipe
Pros:
Simplicity for Networks
Smart Applications (“What you see is what you get”)
Easily Customizable
Cons:
Redundant Code
Every Application has to Implement the Code (Polyglot?)
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
Service
A
Service
B
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
Service
A
Service
B
Proxy Proxy
@anubhavm
Smart Network
Pros:
Little to no Application Code changes are required
Features like Traffic Shaping, Service Discovery and Network Policy Control come
out of the Box
Cons:
Smart Network becomes an Implicit Dependency of the Application
Harder to Reason about the Whole System
“Service Mesh”
@anubhavm
“Service Mesh” aka “Smart Network”
Service
A
Service
B
Proxy Proxy
@anubhavm
“Service Mesh” aka “Smart Network”
Service
A
Service
B
Proxy Proxy
Configure
@anubhavm
“Service Mesh” aka “Smart Network”
Service
A
Service
B
Proxy Proxy
Configure
Two parts
@anubhavm
Separation of Control and Data Plane
Control Plane
Data Plane
@anubhavm
Separation of Control and Data Plane
Control Plane
Data Plane
• Traffic Routing / Shaping
• Configuring the Data Plane
• Policy Enforcement
• Provide Service Discovery Data to Data Plane
@anubhavm
Separation of Control and Data Plane
Control Plane
Data Plane
@anubhavm
Separation of Control and Data Plane
Control Plane
Data Plane
• Forward Request from the Applications
• Health Checking
• Load Balancing
• Circuit Breaking
• Timeouts
• Retries
• Authentication
• Authorization
@anubhavm
Separation of Control and Data Plane
Control Plane
Data Plane
…..
• Forward Request from the Applications
• Health Checking
• Load Balancing
• Circuit Breaking
• Timeouts
• Retries
• Authentication
• Authorization
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
@anubhavm
Smart Networking - First Principles
Dumb Pipe or Smart Network
Protocol Awareness
Layer 4 vs Layer 7
@anubhavm
Protocol Awareness
Layer 4 vs Layer 7
TCP, UDP vs HTTP “Universally” Compatible
High Performance
Difficult to provide Sophisticated
request aware features
Layer 4
@anubhavm
Protocol Awareness
Layer 4 vs Layer 7
TCP, UDP vs HTTP Perform complex routing decisions
Header and Path based routing
Can yield lower performance
Layer 7
Consul as the Control Plane
@anubhavm
Service Mesh for Microservices
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
@anubhavm
Consul Usage
Launched in 2014
12K+ GitHub Stars
1M+ Downloads monthly
Customers running 50,000+ agents
@anubhavm
Public Users
Architecture
@anubhavm
Single Data Center
CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT
SERVER SERVER SERVER
REPLICATION REPLICATION
RPC
RPC
LAN GOSSIP
@anubhavm
Multi Data Center
CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT
SERVER SERVER SERVER
REPLICATION REPLICATION
RPC
RPC
LAN GOSSIP
SERVERSERVER SERVER
REPLICATION REPLICATION
WAN GOSSIP
@anubhavm
Service Mesh for Microservices
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
@anubhavm
Service Discovery
Registry of Nodes, Services, Checks
DNS API
HTTP API
Web UI
T E R M I N A L
$ dig llama.node.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> testing-llama.node.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64443
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;testing-llama.node.consul.IN A
;; ANSWER SECTION:
testing-llama.node.consul. 0 IN A 10.1.1.148
@anubhavm
@anubhavm
Service Configuration
Hierarchical Key/Value Store
HTTP API
Long-polling / Edge trigger
Locking
Exercises
@anubhavm
Workstations
Claim your workstation!
https://hashi.co/velocity-new-york
@anubhavm
Excercise: SSH into your workstations
SSH into your workstation using the provided credentials.
ssh servicemesh@<your.ip.address>

password: veloc1ty2018
Run consul members command to see what happens!
Your tutorial working directory will be /workstation/consul
T E R M I N A L
$ consul members
Node Address Status Type Build Protocol DC Segment
velocity-server-0 10.1.1.73:8301 alive server 1.2.3 2 dc1 <all>
velocity-server-1 10.1.2.16:8301 alive server 1.2.3 2 dc1 <all>
velocity-server-2 10.1.1.164:8301 alive server 1.2.3 2 dc1 <all>
velocity-ant 10.1.1.82:8301 alive client 1.2.3 2 dc1 <default>
velocity-badger 10.1.2.22:8301 alive client 1.2.3 2 dc1 <default>
WA R N I N G You are sharing a cluster
Let’s be nice to each other.
Service Discovery (DNS)
@anubhavm
Service Discovery - DNS Interface
Consul's DNS interface is zero touch
Randomized Round-Robin DNS
Filters on Health Checks
T E R M I N A L
$ dig llama.node.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> testing-llama.node.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64443
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;testing-llama.node.consul.IN A
;; ANSWER SECTION:
testing-llama.node.consul. 0 IN A 10.1.1.148
@anubhavm
Exercise: Query Service
Query for consul service information using dig and the DNS
interface.
HINT: Remember the DNS naming format is
{service_name}.service.consul
T E R M I N A L
$ dig consul.service.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> consul.service.consul
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9334
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;consul.service.consul. IN A
;; ANSWER SECTION:
consul.service.consul. 0 IN A 10.1.1.164
consul.service.consul. 0 IN A 10.1.1.73
consul.service.consul. 0 IN A 10.1.2.16
;; ADDITIONAL SECTION:
consul.service.consul. 0 IN TXT "consul-network-segment="
consul.service.consul. 0 IN TXT "consul-network-segment="
consul.service.consul. 0 IN TXT "consul-network-segment="
T E R M I N A L
$ dig +short consul.service.consul
10.1.1.164
10.1.2.16
10.1.1.73
@anubhavm
Registering Services
Services are registered using JSON definition or via the HTTP
API.
JSON files are put into a dot-d directory and loaded by Consul.
{
"service": {
"name": "my-service",
"tags": ["tag-1", "tag-2"],
"port": 1234
}
}
C O D E E D I T O R
{
"service": {
"name": "my-service",
"tags": ["tag-1", "tag-2"],
"port": 1234
}
}
C O D E E D I T O R
Exposed via DNS and HTTP APIs
Referred to as the "logical service" name
dig my-service.service.consul
{
"service": {
"name": "my-service",
"tags": ["tag-1", "tag-2"],
"port": 1234
}
}
C O D E E D I T O R
Exposed via DNS and HTTP APIs
dig tag-1.my-service.service.consul
{
"service": {
"name": "my-service",
"tags": ["tag-1", "tag-2"],
"port": 1234
}
}
C O D E E D I T O R
Exposed via DNS and HTTP APIs
dig SRV my-service.service.consul
Service Discovery (CLI)
@anubhavm
Service Discovery - Consul CLI
Consul CLI provides basic interactions with service discovery
Do not use the CLI to build tooling (use API instead)
Allows easily querying services
Currently only supports the catalog
@anubhavm
Exercise: Get Help
Run consul catalog -h to see the list of available CLI
service discovery commands.
T E R M I N A L
$ consul catalog -h
Usage: consul catalog <subcommand> [options] [args]
This command has subcommands for interacting with Consul's catalog. The
catalog should not be confused with the agent, although the APIs and
responses may be similar.
Here are some simple examples, and more detailed examples are available
in the subcommands or the documentation.
List all datacenters:
$ consul catalog datacenters
List all nodes:
$ consul catalog nodes
List all services:
$ consul catalog services
.....
@anubhavm
Exercise: List Services with Tags
List all registered services with their tags using the service
discovery CLI.
T E R M I N A L
$ consul catalog services -tags
consul
counting velocity
counting-proxy
dashboard velocity
dashboard-proxy
fabio
http
nomad http,rpc,serf
nomad-client http
K/V Store
@anubhavm
K/V Store
Highly-available, globally accessible key-value store
Folder-like architecture allows for easy organization
Optional ACLs can enforce policy and access
Accessible via HTTP API (no DNS interface)
Can be used via the CLI or via a tool like curl
K/V Store: Use Cases
@anubhavm
K/V Store: Use Cases
Runtime configuration data
Secrets or sensitive application data (eg. Vault’s encrypted data)
@anubhavm
K/V Store: Use Cases
Runtime configuration data
Secrets or sensitive application data (eg. Vault’s encrypted data)
T E R M I N A L
$ consul kv put <KEY> <DATA>
Success! Data written to: <KEY>
$ curl -X PUT -d <DATA> http://localhost:8500/v1/kv/<KEY>
true
T E R M I N A L
$ consul kv get <KEY>
<DATA>
$ curl http://localhost:8500/v1/kv/<KEY>
@anubhavm
Exercise: Create KV Data
Create two new key-value pairs in the store.
Keep in mind that everyone is using the same Consul servers, so
choose a unique name that won't conflict with another user.
Read those values back out.
T E R M I N A L
$ consul kv put anubhavmishra/velocity hello
Success! Data written to: anubhavmishra/velocity
$ consul kv get anubhavmishra/velocity
hello
Consul Template
@anubhavm
Consul Template: A Helper tool for Consul
Consul Template handles the HTTP API flow with Consul
Retrieves keys and services from Consul and renders them into a
template
Optionally integration with HashiCorp Vault as well
@anubhavm
Consul Template: Architecture
{{ key “hello/world“ }}
CONSUL TEMPLATE
CONSUL
value
FILE
1
2
3
@anubhavm
Exercise: Validate Consul Template
Validate Consul Template is installed and configured.
T E R M I N A L
$ consul-template -h
Usage: consul-template [options]
Watches a series of templates on the file system, writing new changes when
Consul is updated. It runs until an interrupt is received unless the -once
flag is specified.
Options:
-config=<path>
Sets the path to a configuration file or folder on disk. This can be
specified multiple times to load multiple files or folders. If multiple
values are given, they are merged left-to-right, and CLI arguments take
the top-most precedence.
-consul-addr=<address>
Sets the address of the Consul instance
@anubhavm
Exercise: Create Template
Create and execute a Consul Template template that iterates over
all the healthy services named "consul" and prints out the IP
address.
HINT: Consul Template's documentation is very verbose and
probably has examples that you can follow.
{{ range service “consul" }}
{{ .Address }}
{{ end }}
C O D E E D I T O R
T E R M I N A L
$ consul-template -dry —template=in.tpl
>
10.1.1.13
10.1.2.250
10.1.1.36
@anubhavm
“Smart Proxy” with NGINX and Consul
Similar to AirBnB’s “Smart Stack”
Configure NGINX dynamically using Consul’s service catalog
Make the simplest form of a “Smart Proxy”
Use Consul Template as the helper tool to achieve this
@anubhavm
“Smart Nginx”
server {
listen 5051;
server {
listen 5050;
.....
NGINX
@anubhavm
“Smart NGINX”
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE A
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE B
:8080
10.0.0.1 10.0.0.2
@anubhavm
“Smart NGINX”
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE A
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE B
:8080
https://10.0.0.2:5051/service/service-b/hello
10.0.0.1 10.0.0.2
@anubhavm
“Smart NGINX”
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE A
server {
listen 5051;
server {
listen 5050;
.....
NGINX
SERVICE B
:8080
https://10.0.0.2:5051/service/service-b/hello
10.0.0.1 10.0.0.2
@anubhavm
Exercise: Validate NGINX
Validate NGINX is installed and configured.
T E R M I N A L
$ nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
@anubhavm
Exercise Goal
{{ key “hello/world“ }}
CONSUL TEMPLATE
CONSUL
server {
.....
NGINX
SERVICE
@anubhavm
Counting Application
For the purpose of this tutorial we will be using a simple Golang
application called “counting-service”.
The application is already installed on your workstations can be
started by typing the following command in your shell:
sudo service counting start
T E R M I N A L
$ sudo service counting start
$ curl http://localhost:9001
{“count":8,"hostname":"velocity-ant.node.consul"}



$ curl http://localhost:9001/health

Hello, you've hit /health
@anubhavm
Exercise: Register Counting Service in Consul
Register a new service named “counting” with tags “velocity”,
running on port 9001.
Query that service using the DNS interface.


Note: Use consul reload command to reload Consul.
T E R M I N A L
$ vim /workstation/consul/counting.json



# INSERT PORT AND HEALTH CHECK ENDPOINT



$ sudo mv /workstation/consul/counting.json /etc/consul.d/counting.json
$ ls /etc/consul.d/
{
"service": {
"name": “counting",
"tags": [“velocity-ant"],
"port": 9001,
"check": {
"id": "counting-check",
"http": "http://localhost:9001/health",
"method": "GET",
"interval": "1s",
"timeout": "1s"
}
}
}
C O D E E D I T O R
T E R M I N A L
$ consul reload
Configuration reload triggered
$ dig $(identity).counting.service.consul
@anubhavm
Exercise: Create a NGINX Template
Create and execute a Consul Template template that iterates over
all services that are tagged as “velocity” and create NGINX
backends for them.
T E R M I N A L
$ cd /workstation/consul/nginx
$ vim nginx.conf.tpl
T E R M I N A L
$ consul-template -template=nginx.conf.tpl -dry
{
"service": {
"name": "counting",
"tags": ["velocity-ant", "velocity"],
"port": 9001,
"check": {
"id": "counting-check",
"http": "http://localhost:9001/health",
"method": "GET",
"interval": "1s",
"timeout": "1s"
}
}
}
C O D E E D I T O R
T E R M I N A L
$ consul-template -template=nginx.conf.tpl -dry
@anubhavm
Exercise: Create Consul Template Config file
Create a config file for Consul Template that can be used to supply
NGINX with the dynamic configuration and then reload it.
T E R M I N A L
$ sudo vim /etc/consul.d/templates/nginx-smart-router.json
log_level = "info"
wait {
min = "5s"
max = "600s"
}
max_stale = "1m"
template {
source = "/etc/consul.d/templates/template/nginx.conf.tpl"
destination ="/etc/nginx/sites-available/nginx-smart-router.conf"
command = "nginx -s reload"
}
C O D E E D I T O R
T E R M I N A L
# Move nginx.conf.tpl to /etc/consul.d/templates/template/nginx.conf.tpl
$ sudo mv nginx.conf.tpl /etc/consul.d/templates/template/nginx.conf.tpl
# Open consul-template systemd configuration and supply it the configuration

$ sudo vim /etc/systemd/system/consul-template.service
[Unit]
Description=Template rendering, notifier, and supervisor for HashiCorp Consul and
Vault data
Requires=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/consul-template -config /etc/consul.d/templates/nginx-
smart-router.json
ExecReload=/bin/kill -HUP
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
[Unit]
Description=Template rendering, notifier, and supervisor for HashiCorp Consul and
Vault data
Requires=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/consul-template -config /etc/consul.d/templates/nginx-
smart-router.json
ExecReload=/bin/kill -HUP
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
T E R M I N A L
$ sudo systemctl daemon-reload
$ sudo service consul-template start
T E R M I N A L
$ cd /etc/nginx/sites-enabled
$ sudo ln -s /etc/nginx/sites-available/nginx-smart-router.conf nginx-smart-router
$ sudo service nginx restart
@anubhavm
Exercise: Request Counting Service via “Smart NGINX”
Make a request to the counting service using the newly configured
NGINX router.
HINT: Use the local port 5050
T E R M I N A L
$ curl http://localhost:5050/service/counting/
{“count":1,"hostname":"velocity-badger.node.consul"}
T E R M I N A L
# Try the -i flag in curl to include the protocol headers
$ curl -i http://localhost:5050/service/counting/
@anubhavm
Exercise: Use the Dashboard Service to Connect to Counting Service
Explore the Dashboard service on your workstations. Start the
service and register it in Consul.
T E R M I N A L
$ vim /etc/systemd/system/dashboard.service
[Unit]
Description=An simple dashboard service
Requires=network-online.target
After=network-online.target
[Service]
Environment=PORT=9002
Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/
ExecStart=/usr/local/bin/dashboard-service
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
[Unit]
Description=An simple dashboard service
Requires=network-online.target
After=network-online.target
[Service]
Environment=PORT=9002
Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/
ExecStart=/usr/local/bin/dashboard-service
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
T E R M I N A L
$ cp /workstation/consul/dashboard.json /etc/consul.d/dashboard.json
$ vim /etc/consul.d/dashboard.json
{
"service": {
"name": "dashboard",
"tags": ["velocity-ant"],
"port": 9002,
"check": {
"id": "dashboard-check",
"http": "http://localhost:9002/health",
"method": "GET",
"interval": "1s",
"timeout": "1s"
}
}
}
C O D E E D I T O R
T E R M I N A L
$ sudo service dashboard start
$ consul reload
@anubhavm
Exercise: Verify Dashboard Application
Open the dashboard application and make sure it is able to
connect to the counting service via “Smart NGINX”.
Your dashboard application will be available at the following URL:
http://{workstation_ip}:9002
@anubhavm
Use Consul K/V as a Control Plane for NGINX
Consul K/V store can be used to store runtime configuration for
the proxy.
Consul Template will watch for these values to change, if they do
then it will immediately make them available for the proxy.
T E R M I N A L
$ while true;do curl -i http://localhost:5050/service/counting/;sleep 0.5;done
T E R M I N A L
$ consul kv put config/global/router/prefer-local-routing 1
@anubhavm
Runtime Configuration
Consul K/V store can be used to store runtime configuration for
the proxy.
These can extend to things like storing values for request retries,
rate limits, etc.
@anubhavm
“Smart Proxy” with X and Consul
This approach can be extended to other proxies like HAProxy,
Apache2, etc.
This approach will also work with containers.
Fabio
@anubhavm
Fabio: A Consul Load Balancer
Fabio integrates with Consul and acts as a load balancer for all
healthy services in a given name.
HTTP(S) and TCP router
Developed at Ebay and used by Ebay, kijiji
Github Repository: https://github.com/fabiolb/fabio
Website: https://fabiolb.net/
@anubhavm
Exercise: Use Fabio as an Ingress into Nomad
Run the counting service using a cluster scheduler (in this case we
will use Nomad).
Use Fabio to get to the counting service using host headers.
T E R M I N A L
$ cd /workstation/nomad
$ vim counting-service.nomad
job "counting-service-velocity-badger" {
datacenters = ["dc1"]
group "counting-service" {
count = 1
task "web" {
driver = "docker"
config {
image = "anubhavmishra/counting-service"
port_map = {
http = 9001
}
}
.....
service {
name = "counting-service"
port = "http"
tags = [
"velocity-badger",
"velocity",
"urlprefix-counting-service.hashicorp.live/",
C O D E E D I T O R
job "counting-service-velocity-badger" {
.....
service {
name = "counting-service"
port = "http"
tags = [
"velocity-badger",
"velocity",
"urlprefix-counting-service.hashicorp.live/",
]
check {
type = "http"
path = "/health"
interval = "2s"
timeout = "2s"
}
}
}
}
}
C O D E E D I T O R
T E R M I N A L
$ nomad run counting-service.nomad
$ nomad status counting-service
T E R M I N A L
$ curl -i -H 'Host: counting-service.hashicorp.live' http://localhost:9999
HTTP/1.1 200 OK
Content-Length: 37
Content-Type: text/plain; charset=utf-8
Date: Fri, 28 Sep 2018 19:09:01 GMT
{“count":2,"hostname":"09cb1e97a2bf"}

# Access your application using the internet

$ curl -i -H 'Host: counting-service.hashicorp.live' http://fabio.hashicorp.live

@anubhavm
Fabio: A Consul Load Balancer
Fabio feels like a “global” load balancer since it spans both, VMs
and Containers!
@anubhavm
Service Mesh for Microservices
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
@anubhavm
Service Mesh for Microservices
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
@anubhavm
Service Mesh for Microservices
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
Zero Trust Networks!
Consul Connect
@anubhavm
Consul Connect
Service Access Graph
Certificate Distribution
Application Integration
@anubhavm
Service Access Graph
Intentions to Allow/Deny Communication
Source and Destination Service
Scale Independent
Managed with CLI, API, UI, Terraform
T E R M I N A L
$ consul intention create -deny web '*'
Created: web => * (deny)
$ consul intention create -allow web db
Created: web => db (allow)
@anubhavm
@anubhavm
Certificate Distribution
Transport Layer Security (TLS)
Service Identity
Encryption of all traffic
@anubhavm
Certificate Format
X.509 Certificate
SPIFFE Compatible
@anubhavm
Application Integration
Consul Client for Service Graph and Certificates
Sidecar Proxies
Native Integrations
@anubhavm
Sidecar Proxy Integration
No Code Modification
Minimal Performance Overhead
Operational Flexibility
@anubhavm
Sidecar Proxies
ClientProxy
App
Configure
Connect
ProxyClient
App
Configure
Connect
@anubhavm
Pluggable Proxies
Client
App
Configure
Connect
Client
App
Configure
Connect
@anubhavm
Pluggable Proxies
Client
App
Configure
Connect
Client
App
Configure
Connect
Coming soon!
{
"service": "web",
"connect": {
"proxy": {
"config": {
"upstreams": [{
"destination_name": "redis",
"local_bind_port": 1234
}]
}
}
}
}
C O D E E D I T O R
@anubhavm
ProxyClient
App
Configure
Connect localhost:1234
Connect to
upstream redis
T E R M I N A L
$ consul connect proxy 
-service web 
-upstream postgresql:8181
$ psql -h 127.0.0.1 -p 8181 -U mitchellh mydb
>
@anubhavm
Exercise: Connect Two Service via Consul Connect
Take two services, dashboard and counting service and connect
them over TLS using Consul’s Connect feature.
dashboard counting
mTLS
@anubhavm
Exercise: Connect Two Service via Consul Connect
Edit the dashboard and counting Consul service files to enable
connect.
T E R M I N A L
$ sudo vim /etc/consul.d/counting.json
{
"service": {
"name": "counting",
"tags": ["velocity"],
"port": 9001,
"connect": {
"proxy": {}
},
"check": {
"id": "counting-check",
"http": "http://localhost:9001/health",
"method": "GET",
"interval": "1s",
"timeout": "1s"
}
}
}
C O D E E D I T O R
T E R M I N A L
$ sudo vim /etc/consul.d/dashboard.json
{
"service": {
"name": "dashboard",
"port": 9002,
"tags": [“velocity-ant"],
"connect": {
"proxy": {
"config": {
"upstreams": [
{
"destination_name": "counting",
"local_bind_port": 9003
}
]
}
}
},
"check": {
"id": "dashboard-check",
"http": "http://localhost:9002/health",
"method": "GET",
"interval": "1s",
"timeout": "1s"
C O D E E D I T O R
@anubhavm
Exercise: Connect Two Service via Consul Connect
Edit the dashboard systemd config file to point to the
local_bind_port 9003.
T E R M I N A L
$ vim /etc/systemd/system/dashboard.service
[Unit]
Description=An simple dashboard service
Requires=network-online.target
After=network-online.target
[Service]
Environment=PORT=9002
Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/
ExecStart=/usr/local/bin/dashboard-service
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
[Unit]
Description=An simple dashboard service
Requires=network-online.target
After=network-online.target
[Service]
Environment=PORT=9002
Environment=COUNTING_SERVICE_URL=http://localhost:9003
ExecStart=/usr/local/bin/dashboard-service
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
C O D E E D I T O R
@anubhavm
Exercise: Connect Two Service via Consul Connect
Reload Consul.
Restart dashboard service.
T E R M I N A L
$ consul reload
Configuration reload triggered
$ sudo systemctl daemon-reload
$ sudo service dashboard restart
@anubhavm
Exercise: Verify Dashboard and Counting Services
Use the Consul UI to verify that both, dashboard and counting
services are healthy and running.
Consul UI is located at http://consul.hashicorp.live
HINT: Navigate the “services” tab in the Consul UI and filter for
your node.
T E R M I N A L
$ open http://consul.hashicorp.live
@anubhavm
Exercise: Verify Dashboard Application
Open the dashboard application and make sure it is able to
connect to the counting service via Consul Connect.
Your dashboard application will be available at the following URL:
http://{workstation_ip}:9002
@anubhavm
Exercise: Use “Intentions” to Deny All Access
Use the Consul UI to deny all access to all services.
@anubhavm
Exercise: Connect to a Database Using Consul Connect
Use Consul Connect to open a encrypted connection to a database
running on a VM.
Client will use Consul Connect to spin up a proxy masquerading as
the “web” service, connecting to the “redis-db” service, binding on
local port 8081
T E R M I N A L
$ sudo apt-get install -y redis-tools
$ redis-cli -h
T E R M I N A L
# Instructor will run this command.
$ sudo apt-get install redis-server
# Register redis service in Consul
# Show traffic without Consul Connect.
# Enable Consul Connect.
T E R M I N A L
$ consul connect proxy 
-service web 
-upstream redis-db:6379 &
$ redis-cli
@anubhavm
Data Planes for L4
Encrypted Connections to Databases (TCP)
Proxy Masquerading
@anubhavm
Native Integration
Standard TLS
Negligible Performance Overhead
Requires Code Modification
// Create a Consul API client
client, _ := api.NewClient(api.DefaultConfig())
// Create an instance representing this service.
svc, _ := connect.NewService("my-service", client)
defer svc.Close()
// Creating an HTTP server that serves via Connect
server := &http.Server{
Addr: ":8080",
TLSConfig: svc.ServerTLSConfig(),
// ... other standard fields
}
// Serve!
server.ListenAndServeTLS("", "")
C O D E E D I T O R
@anubhavm
Consul Connect Lambda Integration
Consul’s Connect feature can be used to connect AWS Lambda
functions to services running inside a datacenter (EC2 instances,
RDS databases etc).
DISCLAIMER: THIS IS NOT PRODUCTION READY!
Github Repository: https://github.com/anubhavmishra/consul-connect-lambda
@anubhavm
Consul Connect Lambda Integration
SERVER
Internal Loadbalancer
SERVER
SERVER
LB
App
App
App
App
VPC
Lambda
Function
SDK
API
GATEWAY
Internet
@anubhavm
Consul Connect Lambda Integration
SERVER
Internal Loadbalancer
SERVER
SERVER
LB
App
App
App
App
VPC
Lambda
Function
SDK
API
GATEWAY
Internet Mutual TLS
Demo
@anubhavm
Consul Connect
Service Access Graph. Intentions allow or deny communication of
logical services.
Certificate Distribution. Standard TLS certificates with SPIFFE
compatibility.
Application Integration. Native integrations or side car proxies.
Conclusion
@anubhavm
Consul for Service Mesh Control Plane
Service Discovery. Connect services with a dynamic registry
Service Configuration. Configure services with runtime configs
Service Segmentation. Secure services based on identity
Pluggable Control Plane and Data Plane.
@anubhavm
Useful Links
• Envoy Consul Service Discovery Service: https://github.com/
anubhavmishra/envoy-consul-sds
• Consul Connect Lambda Integration: https://github.com/
anubhavmishra/consul-connect-lambda
Thanks! I have stickers!
Consul: https://consul.io
@anubhavm

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

(ENT401) Hybrid Infrastructure Integration | AWS re:Invent 2014
(ENT401) Hybrid Infrastructure Integration | AWS re:Invent 2014(ENT401) Hybrid Infrastructure Integration | AWS re:Invent 2014
(ENT401) Hybrid Infrastructure Integration | AWS re:Invent 2014
 
Introduction to Virtual Kubelet
Introduction to Virtual KubeletIntroduction to Virtual Kubelet
Introduction to Virtual Kubelet
 
AWS re:Invent 2016: Media Delivery from the Cloud: Integrated AWS Solutions f...
AWS re:Invent 2016: Media Delivery from the Cloud: Integrated AWS Solutions f...AWS re:Invent 2016: Media Delivery from the Cloud: Integrated AWS Solutions f...
AWS re:Invent 2016: Media Delivery from the Cloud: Integrated AWS Solutions f...
 
Understanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
Understanding the New Enterprise Multi-Cloud Backbone for DevOps EngineersUnderstanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
Understanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
 
Multitenancy on EKS
Multitenancy on EKSMultitenancy on EKS
Multitenancy on EKS
 
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
 
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWSServerless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
 
Demystifying Terraform 012
Demystifying Terraform 012Demystifying Terraform 012
Demystifying Terraform 012
 
AWS re:Invent 2016: Mitigating DDoS Attacks on AWS: Five Vectors and Four Use...
AWS re:Invent 2016: Mitigating DDoS Attacks on AWS: Five Vectors and Four Use...AWS re:Invent 2016: Mitigating DDoS Attacks on AWS: Five Vectors and Four Use...
AWS re:Invent 2016: Mitigating DDoS Attacks on AWS: Five Vectors and Four Use...
 
Meetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practicesMeetup #4: AWS ELB Deep dive & Best practices
Meetup #4: AWS ELB Deep dive & Best practices
 
(ENT308) Best Practices for Implementing Hybrid Architecture Solutions | AWS ...
(ENT308) Best Practices for Implementing Hybrid Architecture Solutions | AWS ...(ENT308) Best Practices for Implementing Hybrid Architecture Solutions | AWS ...
(ENT308) Best Practices for Implementing Hybrid Architecture Solutions | AWS ...
 
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
 
Modern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with NomadModern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with Nomad
 
Practical Guide to Securing Kubernetes
Practical Guide to Securing KubernetesPractical Guide to Securing Kubernetes
Practical Guide to Securing Kubernetes
 
Governance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad ClusterGovernance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad Cluster
 
Hashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs EnterpriseHashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs Enterprise
 
An Overview to Networking in the AWS Cloud for Education [Webinar Slides]
An Overview to Networking in the AWS Cloud for Education [Webinar Slides]An Overview to Networking in the AWS Cloud for Education [Webinar Slides]
An Overview to Networking in the AWS Cloud for Education [Webinar Slides]
 
(ARC203) Expanding Your Data Center with Hybrid Infrastructure | AWS re:Inven...
(ARC203) Expanding Your Data Center with Hybrid Infrastructure | AWS re:Inven...(ARC203) Expanding Your Data Center with Hybrid Infrastructure | AWS re:Inven...
(ARC203) Expanding Your Data Center with Hybrid Infrastructure | AWS re:Inven...
 
Aws Architecture Fundamentals | Dallas
Aws Architecture Fundamentals | DallasAws Architecture Fundamentals | Dallas
Aws Architecture Fundamentals | Dallas
 
Introduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best PracticesIntroduction to AWS VPC, Guidelines, and Best Practices
Introduction to AWS VPC, Guidelines, and Best Practices
 

Ähnlich wie Smart networking with service meshes

Developing Applications with a Micro Service Architecture - Chris Richardson
Developing Applications with a Micro Service Architecture - Chris RichardsonDeveloping Applications with a Micro Service Architecture - Chris Richardson
Developing Applications with a Micro Service Architecture - Chris Richardson
JAXLondon2014
 
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
Aruba, a Hewlett Packard Enterprise company
 

Ähnlich wie Smart networking with service meshes (20)

Forward Networks - Networking Field Day 13 presentation
Forward Networks - Networking Field Day 13 presentationForward Networks - Networking Field Day 13 presentation
Forward Networks - Networking Field Day 13 presentation
 
Forward Networks - Networking Field Day 13 presentation
Forward Networks - Networking Field Day 13 presentationForward Networks - Networking Field Day 13 presentation
Forward Networks - Networking Field Day 13 presentation
 
I'm a developer; should I care about a service mesh?
I'm a developer; should I care about a service mesh?I'm a developer; should I care about a service mesh?
I'm a developer; should I care about a service mesh?
 
OSCON 2019 - I'm a Developer, should I care about a service mesh?
OSCON 2019 - I'm a Developer, should I care about a service mesh?OSCON 2019 - I'm a Developer, should I care about a service mesh?
OSCON 2019 - I'm a Developer, should I care about a service mesh?
 
Networking @Scale'19 - Getting a Taste of Your Network - Sergey Fedorov
Networking @Scale'19 - Getting a Taste of Your Network - Sergey FedorovNetworking @Scale'19 - Getting a Taste of Your Network - Sergey Fedorov
Networking @Scale'19 - Getting a Taste of Your Network - Sergey Fedorov
 
Aruba OS 6.4 Command Line Interface Reference Guide
Aruba OS 6.4 Command Line Interface Reference GuideAruba OS 6.4 Command Line Interface Reference Guide
Aruba OS 6.4 Command Line Interface Reference Guide
 
Consul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesConsul: Service Mesh for Microservices
Consul: Service Mesh for Microservices
 
Dynamic Service Chaining
Dynamic Service Chaining Dynamic Service Chaining
Dynamic Service Chaining
 
Access Management with Aruba ClearPass #AirheadsConf Italy
Access Management with Aruba ClearPass #AirheadsConf ItalyAccess Management with Aruba ClearPass #AirheadsConf Italy
Access Management with Aruba ClearPass #AirheadsConf Italy
 
Cisco Connect Ottawa 2018 consuming public and private clouds
Cisco Connect Ottawa 2018 consuming public and private cloudsCisco Connect Ottawa 2018 consuming public and private clouds
Cisco Connect Ottawa 2018 consuming public and private clouds
 
Demystifying Service Mesh
Demystifying Service MeshDemystifying Service Mesh
Demystifying Service Mesh
 
PostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consulPostgreSQL High-Availability and Geographic Locality using consul
PostgreSQL High-Availability and Geographic Locality using consul
 
21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIO21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIO
 
Breakout - Airheads Macau 2013 - ClearPass Access Management Basics
Breakout - Airheads Macau 2013 - ClearPass Access Management Basics Breakout - Airheads Macau 2013 - ClearPass Access Management Basics
Breakout - Airheads Macau 2013 - ClearPass Access Management Basics
 
BYOD with ClearPass
BYOD with ClearPassBYOD with ClearPass
BYOD with ClearPass
 
#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architecture#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architecture
 
Developing Applications with a Micro Service Architecture - Chris Richardson
Developing Applications with a Micro Service Architecture - Chris RichardsonDeveloping Applications with a Micro Service Architecture - Chris Richardson
Developing Applications with a Micro Service Architecture - Chris Richardson
 
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
Byod and guest access workshop enabling byod carlos gomez gallego_network ser...
 
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
KubeCon EU 2016: Creating an Advanced Load Balancing Solution for Kubernetes ...
 
Pass4sure 640-864 Questions Answers
Pass4sure 640-864 Questions AnswersPass4sure 640-864 Questions Answers
Pass4sure 640-864 Questions Answers
 

Mehr von Mitchell Pronschinske

Mehr von Mitchell Pronschinske (20)

Getting Started with Kubernetes and Consul
Getting Started with Kubernetes and ConsulGetting Started with Kubernetes and Consul
Getting Started with Kubernetes and Consul
 
Multi-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul ConnectMulti-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul Connect
 
Code quality for Terraform
Code quality for TerraformCode quality for Terraform
Code quality for Terraform
 
Dynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD PipelinesDynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD Pipelines
 
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on AzureMigrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
 
Empowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorpEmpowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorp
 
Automate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corpAutomate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corp
 
Vault 1.5 Overview
Vault 1.5 OverviewVault 1.5 Overview
Vault 1.5 Overview
 
Using new sentinel features in terraform cloud
Using new sentinel features in terraform cloudUsing new sentinel features in terraform cloud
Using new sentinel features in terraform cloud
 
Military Edge Computing with Vault and Consul
Military Edge Computing with Vault and ConsulMilitary Edge Computing with Vault and Consul
Military Edge Computing with Vault and Consul
 
Unlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub ActionsUnlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub Actions
 
Vault 1.4 integrated storage overview
Vault 1.4 integrated storage overviewVault 1.4 integrated storage overview
Vault 1.4 integrated storage overview
 
Unlocking the Cloud Operating Model
Unlocking the Cloud Operating ModelUnlocking the Cloud Operating Model
Unlocking the Cloud Operating Model
 
Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)
 
Integrating Terraform and Consul
Integrating Terraform and ConsulIntegrating Terraform and Consul
Integrating Terraform and Consul
 
Unlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: DeploymentUnlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: Deployment
 
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp Vault
 
Moving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on AzureMoving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on Azure
 
Remote Culture at HashiCorp
Remote Culture at HashiCorpRemote Culture at HashiCorp
Remote Culture at HashiCorp
 
Rapid Infrastructure in Hybrid Environments
Rapid Infrastructure in Hybrid EnvironmentsRapid Infrastructure in Hybrid Environments
Rapid Infrastructure in Hybrid Environments
 

Kürzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Smart networking with service meshes

  • 1. Smart Networking with Service Meshes aka What is this “Service Mesh” hype about? Developer Advocate, HashiCorp @anubhavm Anubhav Mishra
  • 5. @anubhavm Anubhav Mishra Developer Advocate, HashiCorp Atlan&s Gopher Artwork by Ashley McNamara
  • 6. @anubhavm Anubhav Mishra Developer Advocate, HashiCorp Atlan&s Gopher Artwork by Ashley McNamara
  • 7. PROVISION, SECURE AND RUN ANY INFRASTRUCTURE Nomad Consul Vault Vagrant Packer Terraform Consul Enterprise Terraform Enterprise Vault Enterprise PRODUCT SUITEOSS TOOL SUITE RUN Applications SECURE Application Infrastructure PROVISION Infrastructure FOR INDIVIDUALS FOR TEAMS Nomad Enterprise
  • 8. @anubhavmBlog Post Link: https://www.hashicorp.com/blog/smart-networking-with-consul-and-service-meshes
  • 10. @anubhavm Agenda 1. Introduction to “Smart Networking” and “Service Mesh” 2. Introduction to HashiCorp Consul 3. Architecture and overview of Consul 4. Exercises (Hands-On Lab) • Exploring Service Discovery, K/V Store, and Consul Template • NGINX and Consul (Smart Proxy) • Fabio and Consul (Smart Networking in containers) • Consul Connect (Service Mesh) • Consul Connect for Service to Service Communication • Consul Connect for Service to Database Communication • Consul Connect for Serverless Applications 5. Conclusion 6. Discussion / Q&A
  • 20. @anubhavm Service A Service B Cert: serviceA.foo.com Cert: serviceB.foo.com Assigning IdentityMutual TLS
  • 21. @anubhavm Service A Service B Cert: serviceA.foo.com Cert: serviceB.foo.com Authorizing trafficMutual TLS Allow?
  • 22. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness
  • 23. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness
  • 24. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness Service A Service B
  • 25. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness Service A Service B Ribbon
  • 26. @anubhavm Dumb Pipe Pros: Simplicity for Networks Smart Applications (“What you see is what you get”) Easily Customizable Cons: Redundant Code Every Application has to Implement the Code (Polyglot?)
  • 27. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness Service A Service B
  • 28. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness Service A Service B Proxy Proxy
  • 29. @anubhavm Smart Network Pros: Little to no Application Code changes are required Features like Traffic Shaping, Service Discovery and Network Policy Control come out of the Box Cons: Smart Network becomes an Implicit Dependency of the Application Harder to Reason about the Whole System
  • 31. @anubhavm “Service Mesh” aka “Smart Network” Service A Service B Proxy Proxy
  • 32. @anubhavm “Service Mesh” aka “Smart Network” Service A Service B Proxy Proxy Configure
  • 33. @anubhavm “Service Mesh” aka “Smart Network” Service A Service B Proxy Proxy Configure Two parts
  • 34. @anubhavm Separation of Control and Data Plane Control Plane Data Plane
  • 35. @anubhavm Separation of Control and Data Plane Control Plane Data Plane • Traffic Routing / Shaping • Configuring the Data Plane • Policy Enforcement • Provide Service Discovery Data to Data Plane
  • 36. @anubhavm Separation of Control and Data Plane Control Plane Data Plane
  • 37. @anubhavm Separation of Control and Data Plane Control Plane Data Plane • Forward Request from the Applications • Health Checking • Load Balancing • Circuit Breaking • Timeouts • Retries • Authentication • Authorization
  • 38. @anubhavm Separation of Control and Data Plane Control Plane Data Plane ….. • Forward Request from the Applications • Health Checking • Load Balancing • Circuit Breaking • Timeouts • Retries • Authentication • Authorization
  • 39. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness
  • 40. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness
  • 41. @anubhavm Smart Networking - First Principles Dumb Pipe or Smart Network Protocol Awareness Layer 4 vs Layer 7
  • 42. @anubhavm Protocol Awareness Layer 4 vs Layer 7 TCP, UDP vs HTTP “Universally” Compatible High Performance Difficult to provide Sophisticated request aware features Layer 4
  • 43. @anubhavm Protocol Awareness Layer 4 vs Layer 7 TCP, UDP vs HTTP Perform complex routing decisions Header and Path based routing Can yield lower performance Layer 7
  • 44. Consul as the Control Plane
  • 45.
  • 46. @anubhavm Service Mesh for Microservices Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity
  • 47. @anubhavm Consul Usage Launched in 2014 12K+ GitHub Stars 1M+ Downloads monthly Customers running 50,000+ agents
  • 50. @anubhavm Single Data Center CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT SERVER SERVER SERVER REPLICATION REPLICATION RPC RPC LAN GOSSIP
  • 51. @anubhavm Multi Data Center CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT SERVER SERVER SERVER REPLICATION REPLICATION RPC RPC LAN GOSSIP SERVERSERVER SERVER REPLICATION REPLICATION WAN GOSSIP
  • 52. @anubhavm Service Mesh for Microservices Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity
  • 53. @anubhavm Service Discovery Registry of Nodes, Services, Checks DNS API HTTP API Web UI
  • 54. T E R M I N A L $ dig llama.node.consul ; <<>> DiG 9.10.3-P4-Ubuntu <<>> testing-llama.node.consul ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64443 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1280 ;; QUESTION SECTION: ;testing-llama.node.consul.IN A ;; ANSWER SECTION: testing-llama.node.consul. 0 IN A 10.1.1.148
  • 56. @anubhavm Service Configuration Hierarchical Key/Value Store HTTP API Long-polling / Edge trigger Locking
  • 59. @anubhavm Excercise: SSH into your workstations SSH into your workstation using the provided credentials. ssh servicemesh@<your.ip.address>
 password: veloc1ty2018 Run consul members command to see what happens! Your tutorial working directory will be /workstation/consul
  • 60. T E R M I N A L $ consul members Node Address Status Type Build Protocol DC Segment velocity-server-0 10.1.1.73:8301 alive server 1.2.3 2 dc1 <all> velocity-server-1 10.1.2.16:8301 alive server 1.2.3 2 dc1 <all> velocity-server-2 10.1.1.164:8301 alive server 1.2.3 2 dc1 <all> velocity-ant 10.1.1.82:8301 alive client 1.2.3 2 dc1 <default> velocity-badger 10.1.2.22:8301 alive client 1.2.3 2 dc1 <default>
  • 61. WA R N I N G You are sharing a cluster Let’s be nice to each other.
  • 63. @anubhavm Service Discovery - DNS Interface Consul's DNS interface is zero touch Randomized Round-Robin DNS Filters on Health Checks
  • 64. T E R M I N A L $ dig llama.node.consul ; <<>> DiG 9.10.3-P4-Ubuntu <<>> testing-llama.node.consul ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64443 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1280 ;; QUESTION SECTION: ;testing-llama.node.consul.IN A ;; ANSWER SECTION: testing-llama.node.consul. 0 IN A 10.1.1.148
  • 65. @anubhavm Exercise: Query Service Query for consul service information using dig and the DNS interface. HINT: Remember the DNS naming format is {service_name}.service.consul
  • 66. T E R M I N A L $ dig consul.service.consul ; <<>> DiG 9.10.3-P4-Ubuntu <<>> consul.service.consul ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9334 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 4 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;consul.service.consul. IN A ;; ANSWER SECTION: consul.service.consul. 0 IN A 10.1.1.164 consul.service.consul. 0 IN A 10.1.1.73 consul.service.consul. 0 IN A 10.1.2.16 ;; ADDITIONAL SECTION: consul.service.consul. 0 IN TXT "consul-network-segment=" consul.service.consul. 0 IN TXT "consul-network-segment=" consul.service.consul. 0 IN TXT "consul-network-segment="
  • 67. T E R M I N A L $ dig +short consul.service.consul 10.1.1.164 10.1.2.16 10.1.1.73
  • 68. @anubhavm Registering Services Services are registered using JSON definition or via the HTTP API. JSON files are put into a dot-d directory and loaded by Consul.
  • 69. { "service": { "name": "my-service", "tags": ["tag-1", "tag-2"], "port": 1234 } } C O D E E D I T O R
  • 70. { "service": { "name": "my-service", "tags": ["tag-1", "tag-2"], "port": 1234 } } C O D E E D I T O R Exposed via DNS and HTTP APIs Referred to as the "logical service" name dig my-service.service.consul
  • 71. { "service": { "name": "my-service", "tags": ["tag-1", "tag-2"], "port": 1234 } } C O D E E D I T O R Exposed via DNS and HTTP APIs dig tag-1.my-service.service.consul
  • 72. { "service": { "name": "my-service", "tags": ["tag-1", "tag-2"], "port": 1234 } } C O D E E D I T O R Exposed via DNS and HTTP APIs dig SRV my-service.service.consul
  • 74. @anubhavm Service Discovery - Consul CLI Consul CLI provides basic interactions with service discovery Do not use the CLI to build tooling (use API instead) Allows easily querying services Currently only supports the catalog
  • 75. @anubhavm Exercise: Get Help Run consul catalog -h to see the list of available CLI service discovery commands.
  • 76. T E R M I N A L $ consul catalog -h Usage: consul catalog <subcommand> [options] [args] This command has subcommands for interacting with Consul's catalog. The catalog should not be confused with the agent, although the APIs and responses may be similar. Here are some simple examples, and more detailed examples are available in the subcommands or the documentation. List all datacenters: $ consul catalog datacenters List all nodes: $ consul catalog nodes List all services: $ consul catalog services .....
  • 77. @anubhavm Exercise: List Services with Tags List all registered services with their tags using the service discovery CLI.
  • 78. T E R M I N A L $ consul catalog services -tags consul counting velocity counting-proxy dashboard velocity dashboard-proxy fabio http nomad http,rpc,serf nomad-client http
  • 80. @anubhavm K/V Store Highly-available, globally accessible key-value store Folder-like architecture allows for easy organization Optional ACLs can enforce policy and access Accessible via HTTP API (no DNS interface) Can be used via the CLI or via a tool like curl K/V Store: Use Cases
  • 81. @anubhavm K/V Store: Use Cases Runtime configuration data Secrets or sensitive application data (eg. Vault’s encrypted data)
  • 82. @anubhavm K/V Store: Use Cases Runtime configuration data Secrets or sensitive application data (eg. Vault’s encrypted data)
  • 83. T E R M I N A L $ consul kv put <KEY> <DATA> Success! Data written to: <KEY> $ curl -X PUT -d <DATA> http://localhost:8500/v1/kv/<KEY> true
  • 84. T E R M I N A L $ consul kv get <KEY> <DATA> $ curl http://localhost:8500/v1/kv/<KEY>
  • 85. @anubhavm Exercise: Create KV Data Create two new key-value pairs in the store. Keep in mind that everyone is using the same Consul servers, so choose a unique name that won't conflict with another user. Read those values back out.
  • 86. T E R M I N A L $ consul kv put anubhavmishra/velocity hello Success! Data written to: anubhavmishra/velocity $ consul kv get anubhavmishra/velocity hello
  • 88. @anubhavm Consul Template: A Helper tool for Consul Consul Template handles the HTTP API flow with Consul Retrieves keys and services from Consul and renders them into a template Optionally integration with HashiCorp Vault as well
  • 89. @anubhavm Consul Template: Architecture {{ key “hello/world“ }} CONSUL TEMPLATE CONSUL value FILE 1 2 3
  • 90. @anubhavm Exercise: Validate Consul Template Validate Consul Template is installed and configured.
  • 91. T E R M I N A L $ consul-template -h Usage: consul-template [options] Watches a series of templates on the file system, writing new changes when Consul is updated. It runs until an interrupt is received unless the -once flag is specified. Options: -config=<path> Sets the path to a configuration file or folder on disk. This can be specified multiple times to load multiple files or folders. If multiple values are given, they are merged left-to-right, and CLI arguments take the top-most precedence. -consul-addr=<address> Sets the address of the Consul instance
  • 92. @anubhavm Exercise: Create Template Create and execute a Consul Template template that iterates over all the healthy services named "consul" and prints out the IP address. HINT: Consul Template's documentation is very verbose and probably has examples that you can follow.
  • 93. {{ range service “consul" }} {{ .Address }} {{ end }} C O D E E D I T O R
  • 94. T E R M I N A L $ consul-template -dry —template=in.tpl > 10.1.1.13 10.1.2.250 10.1.1.36
  • 95. @anubhavm “Smart Proxy” with NGINX and Consul Similar to AirBnB’s “Smart Stack” Configure NGINX dynamically using Consul’s service catalog Make the simplest form of a “Smart Proxy” Use Consul Template as the helper tool to achieve this
  • 96. @anubhavm “Smart Nginx” server { listen 5051; server { listen 5050; ..... NGINX
  • 97. @anubhavm “Smart NGINX” server { listen 5051; server { listen 5050; ..... NGINX SERVICE A server { listen 5051; server { listen 5050; ..... NGINX SERVICE B :8080 10.0.0.1 10.0.0.2
  • 98. @anubhavm “Smart NGINX” server { listen 5051; server { listen 5050; ..... NGINX SERVICE A server { listen 5051; server { listen 5050; ..... NGINX SERVICE B :8080 https://10.0.0.2:5051/service/service-b/hello 10.0.0.1 10.0.0.2
  • 99. @anubhavm “Smart NGINX” server { listen 5051; server { listen 5050; ..... NGINX SERVICE A server { listen 5051; server { listen 5050; ..... NGINX SERVICE B :8080 https://10.0.0.2:5051/service/service-b/hello 10.0.0.1 10.0.0.2
  • 100. @anubhavm Exercise: Validate NGINX Validate NGINX is installed and configured.
  • 101. T E R M I N A L $ nginx -v nginx version: nginx/1.10.3 (Ubuntu)
  • 102. @anubhavm Exercise Goal {{ key “hello/world“ }} CONSUL TEMPLATE CONSUL server { ..... NGINX SERVICE
  • 103. @anubhavm Counting Application For the purpose of this tutorial we will be using a simple Golang application called “counting-service”. The application is already installed on your workstations can be started by typing the following command in your shell: sudo service counting start
  • 104. T E R M I N A L $ sudo service counting start $ curl http://localhost:9001 {“count":8,"hostname":"velocity-ant.node.consul"}
 
 $ curl http://localhost:9001/health
 Hello, you've hit /health
  • 105. @anubhavm Exercise: Register Counting Service in Consul Register a new service named “counting” with tags “velocity”, running on port 9001. Query that service using the DNS interface. 
 Note: Use consul reload command to reload Consul.
  • 106. T E R M I N A L $ vim /workstation/consul/counting.json
 
 # INSERT PORT AND HEALTH CHECK ENDPOINT
 
 $ sudo mv /workstation/consul/counting.json /etc/consul.d/counting.json $ ls /etc/consul.d/
  • 107. { "service": { "name": “counting", "tags": [“velocity-ant"], "port": 9001, "check": { "id": "counting-check", "http": "http://localhost:9001/health", "method": "GET", "interval": "1s", "timeout": "1s" } } } C O D E E D I T O R
  • 108. T E R M I N A L $ consul reload Configuration reload triggered $ dig $(identity).counting.service.consul
  • 109. @anubhavm Exercise: Create a NGINX Template Create and execute a Consul Template template that iterates over all services that are tagged as “velocity” and create NGINX backends for them.
  • 110. T E R M I N A L $ cd /workstation/consul/nginx $ vim nginx.conf.tpl
  • 111. T E R M I N A L $ consul-template -template=nginx.conf.tpl -dry
  • 112. { "service": { "name": "counting", "tags": ["velocity-ant", "velocity"], "port": 9001, "check": { "id": "counting-check", "http": "http://localhost:9001/health", "method": "GET", "interval": "1s", "timeout": "1s" } } } C O D E E D I T O R
  • 113. T E R M I N A L $ consul-template -template=nginx.conf.tpl -dry
  • 114. @anubhavm Exercise: Create Consul Template Config file Create a config file for Consul Template that can be used to supply NGINX with the dynamic configuration and then reload it.
  • 115. T E R M I N A L $ sudo vim /etc/consul.d/templates/nginx-smart-router.json
  • 116. log_level = "info" wait { min = "5s" max = "600s" } max_stale = "1m" template { source = "/etc/consul.d/templates/template/nginx.conf.tpl" destination ="/etc/nginx/sites-available/nginx-smart-router.conf" command = "nginx -s reload" } C O D E E D I T O R
  • 117. T E R M I N A L # Move nginx.conf.tpl to /etc/consul.d/templates/template/nginx.conf.tpl $ sudo mv nginx.conf.tpl /etc/consul.d/templates/template/nginx.conf.tpl # Open consul-template systemd configuration and supply it the configuration
 $ sudo vim /etc/systemd/system/consul-template.service
  • 118. [Unit] Description=Template rendering, notifier, and supervisor for HashiCorp Consul and Vault data Requires=network-online.target After=network-online.target [Service] ExecStart=/usr/local/bin/consul-template -config /etc/consul.d/templates/nginx- smart-router.json ExecReload=/bin/kill -HUP KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 119. [Unit] Description=Template rendering, notifier, and supervisor for HashiCorp Consul and Vault data Requires=network-online.target After=network-online.target [Service] ExecStart=/usr/local/bin/consul-template -config /etc/consul.d/templates/nginx- smart-router.json ExecReload=/bin/kill -HUP KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 120. T E R M I N A L $ sudo systemctl daemon-reload $ sudo service consul-template start
  • 121. T E R M I N A L $ cd /etc/nginx/sites-enabled $ sudo ln -s /etc/nginx/sites-available/nginx-smart-router.conf nginx-smart-router $ sudo service nginx restart
  • 122. @anubhavm Exercise: Request Counting Service via “Smart NGINX” Make a request to the counting service using the newly configured NGINX router. HINT: Use the local port 5050
  • 123. T E R M I N A L $ curl http://localhost:5050/service/counting/ {“count":1,"hostname":"velocity-badger.node.consul"}
  • 124. T E R M I N A L # Try the -i flag in curl to include the protocol headers $ curl -i http://localhost:5050/service/counting/
  • 125. @anubhavm Exercise: Use the Dashboard Service to Connect to Counting Service Explore the Dashboard service on your workstations. Start the service and register it in Consul.
  • 126. T E R M I N A L $ vim /etc/systemd/system/dashboard.service
  • 127. [Unit] Description=An simple dashboard service Requires=network-online.target After=network-online.target [Service] Environment=PORT=9002 Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/ ExecStart=/usr/local/bin/dashboard-service ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 128. [Unit] Description=An simple dashboard service Requires=network-online.target After=network-online.target [Service] Environment=PORT=9002 Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/ ExecStart=/usr/local/bin/dashboard-service ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 129. T E R M I N A L $ cp /workstation/consul/dashboard.json /etc/consul.d/dashboard.json $ vim /etc/consul.d/dashboard.json
  • 130. { "service": { "name": "dashboard", "tags": ["velocity-ant"], "port": 9002, "check": { "id": "dashboard-check", "http": "http://localhost:9002/health", "method": "GET", "interval": "1s", "timeout": "1s" } } } C O D E E D I T O R
  • 131. T E R M I N A L $ sudo service dashboard start $ consul reload
  • 132. @anubhavm Exercise: Verify Dashboard Application Open the dashboard application and make sure it is able to connect to the counting service via “Smart NGINX”. Your dashboard application will be available at the following URL: http://{workstation_ip}:9002
  • 133. @anubhavm Use Consul K/V as a Control Plane for NGINX Consul K/V store can be used to store runtime configuration for the proxy. Consul Template will watch for these values to change, if they do then it will immediately make them available for the proxy.
  • 134. T E R M I N A L $ while true;do curl -i http://localhost:5050/service/counting/;sleep 0.5;done
  • 135. T E R M I N A L $ consul kv put config/global/router/prefer-local-routing 1
  • 136. @anubhavm Runtime Configuration Consul K/V store can be used to store runtime configuration for the proxy. These can extend to things like storing values for request retries, rate limits, etc.
  • 137. @anubhavm “Smart Proxy” with X and Consul This approach can be extended to other proxies like HAProxy, Apache2, etc. This approach will also work with containers.
  • 138. Fabio
  • 139. @anubhavm Fabio: A Consul Load Balancer Fabio integrates with Consul and acts as a load balancer for all healthy services in a given name. HTTP(S) and TCP router Developed at Ebay and used by Ebay, kijiji Github Repository: https://github.com/fabiolb/fabio Website: https://fabiolb.net/
  • 140. @anubhavm Exercise: Use Fabio as an Ingress into Nomad Run the counting service using a cluster scheduler (in this case we will use Nomad). Use Fabio to get to the counting service using host headers.
  • 141. T E R M I N A L $ cd /workstation/nomad $ vim counting-service.nomad
  • 142. job "counting-service-velocity-badger" { datacenters = ["dc1"] group "counting-service" { count = 1 task "web" { driver = "docker" config { image = "anubhavmishra/counting-service" port_map = { http = 9001 } } ..... service { name = "counting-service" port = "http" tags = [ "velocity-badger", "velocity", "urlprefix-counting-service.hashicorp.live/", C O D E E D I T O R
  • 143. job "counting-service-velocity-badger" { ..... service { name = "counting-service" port = "http" tags = [ "velocity-badger", "velocity", "urlprefix-counting-service.hashicorp.live/", ] check { type = "http" path = "/health" interval = "2s" timeout = "2s" } } } } } C O D E E D I T O R
  • 144. T E R M I N A L $ nomad run counting-service.nomad $ nomad status counting-service
  • 145. T E R M I N A L $ curl -i -H 'Host: counting-service.hashicorp.live' http://localhost:9999 HTTP/1.1 200 OK Content-Length: 37 Content-Type: text/plain; charset=utf-8 Date: Fri, 28 Sep 2018 19:09:01 GMT {“count":2,"hostname":"09cb1e97a2bf"}
 # Access your application using the internet
 $ curl -i -H 'Host: counting-service.hashicorp.live' http://fabio.hashicorp.live

  • 146. @anubhavm Fabio: A Consul Load Balancer Fabio feels like a “global” load balancer since it spans both, VMs and Containers!
  • 147. @anubhavm Service Mesh for Microservices Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity
  • 148. @anubhavm Service Mesh for Microservices Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity
  • 149. @anubhavm Service Mesh for Microservices Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity Zero Trust Networks!
  • 151. @anubhavm Consul Connect Service Access Graph Certificate Distribution Application Integration
  • 152. @anubhavm Service Access Graph Intentions to Allow/Deny Communication Source and Destination Service Scale Independent Managed with CLI, API, UI, Terraform
  • 153. T E R M I N A L $ consul intention create -deny web '*' Created: web => * (deny) $ consul intention create -allow web db Created: web => db (allow)
  • 155. @anubhavm Certificate Distribution Transport Layer Security (TLS) Service Identity Encryption of all traffic
  • 157. @anubhavm Application Integration Consul Client for Service Graph and Certificates Sidecar Proxies Native Integrations
  • 158. @anubhavm Sidecar Proxy Integration No Code Modification Minimal Performance Overhead Operational Flexibility
  • 162. { "service": "web", "connect": { "proxy": { "config": { "upstreams": [{ "destination_name": "redis", "local_bind_port": 1234 }] } } } } C O D E E D I T O R
  • 164. T E R M I N A L $ consul connect proxy -service web -upstream postgresql:8181 $ psql -h 127.0.0.1 -p 8181 -U mitchellh mydb >
  • 165. @anubhavm Exercise: Connect Two Service via Consul Connect Take two services, dashboard and counting service and connect them over TLS using Consul’s Connect feature. dashboard counting mTLS
  • 166. @anubhavm Exercise: Connect Two Service via Consul Connect Edit the dashboard and counting Consul service files to enable connect.
  • 167. T E R M I N A L $ sudo vim /etc/consul.d/counting.json
  • 168. { "service": { "name": "counting", "tags": ["velocity"], "port": 9001, "connect": { "proxy": {} }, "check": { "id": "counting-check", "http": "http://localhost:9001/health", "method": "GET", "interval": "1s", "timeout": "1s" } } } C O D E E D I T O R
  • 169. T E R M I N A L $ sudo vim /etc/consul.d/dashboard.json
  • 170. { "service": { "name": "dashboard", "port": 9002, "tags": [“velocity-ant"], "connect": { "proxy": { "config": { "upstreams": [ { "destination_name": "counting", "local_bind_port": 9003 } ] } } }, "check": { "id": "dashboard-check", "http": "http://localhost:9002/health", "method": "GET", "interval": "1s", "timeout": "1s" C O D E E D I T O R
  • 171. @anubhavm Exercise: Connect Two Service via Consul Connect Edit the dashboard systemd config file to point to the local_bind_port 9003.
  • 172. T E R M I N A L $ vim /etc/systemd/system/dashboard.service
  • 173. [Unit] Description=An simple dashboard service Requires=network-online.target After=network-online.target [Service] Environment=PORT=9002 Environment=COUNTING_SERVICE_URL=http://localhost:5050/service/counting/ ExecStart=/usr/local/bin/dashboard-service ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 174. [Unit] Description=An simple dashboard service Requires=network-online.target After=network-online.target [Service] Environment=PORT=9002 Environment=COUNTING_SERVICE_URL=http://localhost:9003 ExecStart=/usr/local/bin/dashboard-service ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target C O D E E D I T O R
  • 175. @anubhavm Exercise: Connect Two Service via Consul Connect Reload Consul. Restart dashboard service.
  • 176. T E R M I N A L $ consul reload Configuration reload triggered $ sudo systemctl daemon-reload $ sudo service dashboard restart
  • 177. @anubhavm Exercise: Verify Dashboard and Counting Services Use the Consul UI to verify that both, dashboard and counting services are healthy and running. Consul UI is located at http://consul.hashicorp.live HINT: Navigate the “services” tab in the Consul UI and filter for your node.
  • 178. T E R M I N A L $ open http://consul.hashicorp.live
  • 179. @anubhavm Exercise: Verify Dashboard Application Open the dashboard application and make sure it is able to connect to the counting service via Consul Connect. Your dashboard application will be available at the following URL: http://{workstation_ip}:9002
  • 180. @anubhavm Exercise: Use “Intentions” to Deny All Access Use the Consul UI to deny all access to all services.
  • 181. @anubhavm Exercise: Connect to a Database Using Consul Connect Use Consul Connect to open a encrypted connection to a database running on a VM. Client will use Consul Connect to spin up a proxy masquerading as the “web” service, connecting to the “redis-db” service, binding on local port 8081
  • 182. T E R M I N A L $ sudo apt-get install -y redis-tools $ redis-cli -h
  • 183. T E R M I N A L # Instructor will run this command. $ sudo apt-get install redis-server # Register redis service in Consul # Show traffic without Consul Connect. # Enable Consul Connect.
  • 184. T E R M I N A L $ consul connect proxy -service web -upstream redis-db:6379 & $ redis-cli
  • 185. @anubhavm Data Planes for L4 Encrypted Connections to Databases (TCP) Proxy Masquerading
  • 186. @anubhavm Native Integration Standard TLS Negligible Performance Overhead Requires Code Modification
  • 187. // Create a Consul API client client, _ := api.NewClient(api.DefaultConfig()) // Create an instance representing this service. svc, _ := connect.NewService("my-service", client) defer svc.Close() // Creating an HTTP server that serves via Connect server := &http.Server{ Addr: ":8080", TLSConfig: svc.ServerTLSConfig(), // ... other standard fields } // Serve! server.ListenAndServeTLS("", "") C O D E E D I T O R
  • 188. @anubhavm Consul Connect Lambda Integration Consul’s Connect feature can be used to connect AWS Lambda functions to services running inside a datacenter (EC2 instances, RDS databases etc). DISCLAIMER: THIS IS NOT PRODUCTION READY! Github Repository: https://github.com/anubhavmishra/consul-connect-lambda
  • 189. @anubhavm Consul Connect Lambda Integration SERVER Internal Loadbalancer SERVER SERVER LB App App App App VPC Lambda Function SDK API GATEWAY Internet
  • 190. @anubhavm Consul Connect Lambda Integration SERVER Internal Loadbalancer SERVER SERVER LB App App App App VPC Lambda Function SDK API GATEWAY Internet Mutual TLS
  • 191. Demo
  • 192. @anubhavm Consul Connect Service Access Graph. Intentions allow or deny communication of logical services. Certificate Distribution. Standard TLS certificates with SPIFFE compatibility. Application Integration. Native integrations or side car proxies.
  • 194. @anubhavm Consul for Service Mesh Control Plane Service Discovery. Connect services with a dynamic registry Service Configuration. Configure services with runtime configs Service Segmentation. Secure services based on identity Pluggable Control Plane and Data Plane.
  • 195. @anubhavm Useful Links • Envoy Consul Service Discovery Service: https://github.com/ anubhavmishra/envoy-consul-sds • Consul Connect Lambda Integration: https://github.com/ anubhavmishra/consul-connect-lambda
  • 196. Thanks! I have stickers! Consul: https://consul.io @anubhavm