Smart Networking with Service Meshes aka What is this Service Mesh - - PowerPoint PPT Presentation

smart networking with service meshes
SMART_READER_LITE
LIVE PREVIEW

Smart Networking with Service Meshes aka What is this Service Mesh - - PowerPoint PPT Presentation

Smart Networking with Service Meshes aka What is this Service Mesh hype about? Anubhav Mishra Developer Advocate, HashiCorp @anubhavm Anubhav Mishra Developer Advocate, HashiCorp @anubhavm Atlan&s Anubhav Mishra Developer


slide-1
SLIDE 1

Smart Networking with Service Meshes

aka What is this “Service Mesh” hype about?

Developer Advocate, HashiCorp @anubhavm

Anubhav Mishra

slide-2
SLIDE 2

@anubhavm

Anubhav Mishra

Developer Advocate, HashiCorp

slide-3
SLIDE 3

@anubhavm

Anubhav Mishra

Developer Advocate, HashiCorp

Atlan&s

slide-4
SLIDE 4

@anubhavm

Anubhav Mishra

Developer Advocate, HashiCorp

Atlan&s

slide-5
SLIDE 5

@anubhavm

Anubhav Mishra

Developer Advocate, HashiCorp

Atlan&s

Gopher Artwork by Ashley McNamara

slide-6
SLIDE 6

@anubhavm

Anubhav Mishra

Developer Advocate, HashiCorp

Atlan&s

Gopher Artwork by Ashley McNamara

slide-7
SLIDE 7

PROVISION, SECURE AND RUN ANY INFRASTRUCTURE

Nomad Consul Vault Vagrant Packer Terraform

Consul Enterprise Terraform Enterprise Vault Enterprise

PRODUCT SUITE OSS TOOL SUITE

RUN

Applications

SECURE

Application Infrastructure

PROVISION

Infrastructure

FOR INDIVIDUALS FOR TEAMS

Nomad Enterprise

slide-8
SLIDE 8

@anubhavm 

Blog Post Link: https://www.hashicorp.com/blog/smart-networking-with-consul-and-service-meshes

slide-9
SLIDE 9

Agenda

slide-10
SLIDE 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
slide-11
SLIDE 11

“Smart Networking”

slide-12
SLIDE 12

@anubhavm 

Service A Service B

slide-13
SLIDE 13

@anubhavm 

Service A Service B Service B Service B

Multiple Instances ?

slide-14
SLIDE 14

@anubhavm 

Service A Service B Service B Service B

Multiple Instances ? Service Discovery

slide-15
SLIDE 15

@anubhavm 

Service A Service B

slide-16
SLIDE 16

@anubhavm 

Service A Service B

Request Failed

slide-17
SLIDE 17

@anubhavm 

Service A Service B

Request Failed Retries

slide-18
SLIDE 18

@anubhavm 

Service A Service B

slide-19
SLIDE 19

@anubhavm 

Service A Service B

Cert: serviceA.foo.com Cert: serviceB.foo.com Assigning Identity

slide-20
SLIDE 20

@anubhavm 

Service A Service B

Cert: serviceA.foo.com Cert: serviceB.foo.com Assigning Identity Mutual TLS

slide-21
SLIDE 21

@anubhavm 

Service A Service B

Cert: serviceA.foo.com Cert: serviceB.foo.com Authorizing traffjc Mutual TLS Allow?

slide-22
SLIDE 22

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

slide-23
SLIDE 23

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

slide-24
SLIDE 24

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

Service A Service B

slide-25
SLIDE 25

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

Service A Service B

Ribbon

slide-26
SLIDE 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?)

slide-27
SLIDE 27

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

Service A Service B

slide-28
SLIDE 28

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

Service A Service B

Proxy Proxy

slide-29
SLIDE 29

@anubhavm 

Smart Network

Pros: Little to no Application Code changes are required Features like Traffjc Shaping, Service Discovery and Network Policy Control come

  • ut of the Box

Cons: Smart Network becomes an Implicit Dependency of the Application Harder to Reason about the Whole System

slide-30
SLIDE 30

“Service Mesh”

slide-31
SLIDE 31

@anubhavm 

“Service Mesh” aka “Smart Network” Service A Service B

Proxy Proxy

slide-32
SLIDE 32

@anubhavm 

“Service Mesh” aka “Smart Network” Service A Service B

Proxy Proxy

Configure

slide-33
SLIDE 33

@anubhavm 

“Service Mesh” aka “Smart Network” Service A Service B

Proxy Proxy

Configure Two parts

slide-34
SLIDE 34

@anubhavm 

Separation of Control and Data Plane

Control Plane Data Plane

slide-35
SLIDE 35

@anubhavm 

Separation of Control and Data Plane

Control Plane Data Plane

  • Traffjc Routing / Shaping
  • Configuring the Data Plane
  • Policy Enforcement
  • Provide Service Discovery Data to Data Plane
slide-36
SLIDE 36

@anubhavm 

Separation of Control and Data Plane

Control Plane Data Plane

slide-37
SLIDE 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
slide-38
SLIDE 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
slide-39
SLIDE 39

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

slide-40
SLIDE 40

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

slide-41
SLIDE 41

@anubhavm 

Smart Networking - First Principles

Dumb Pipe or Smart Network Protocol Awareness

Layer 4 vs Layer 7

slide-42
SLIDE 42

@anubhavm 

Protocol Awareness

Layer 4 vs Layer 7 TCP, UDP vs HTTP

“Universally” Compatible High Performance Diffjcult to provide Sophisticated request aware features

Layer 4

slide-43
SLIDE 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

slide-44
SLIDE 44

Consul as the Control Plane

slide-45
SLIDE 45
slide-46
SLIDE 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

slide-47
SLIDE 47

@anubhavm 

Consul Usage

Launched in 2014 12K+ GitHub Stars 1M+ Downloads monthly Customers running 50,000+ agents

slide-48
SLIDE 48

@anubhavm 

Public Users

slide-49
SLIDE 49

Architecture

slide-50
SLIDE 50

@anubhavm 

Single Data Center

CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT SERVER SERVER SERVER

REPLICATION REPLICATION RPC RPC LAN GOSSIP

slide-51
SLIDE 51

@anubhavm 

Multi Data Center

CLIENT CLIENT CLIENT CLIENT CLIENT CLIENT SERVER SERVER SERVER

REPLICATION REPLICATION RPC RPC LAN GOSSIP

SERVER SERVER SERVER

REPLICATION REPLICATION WAN GOSSIP

slide-52
SLIDE 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

slide-53
SLIDE 53

@anubhavm 

Service Discovery

Registry of Nodes, Services, Checks DNS API HTTP API Web UI

slide-54
SLIDE 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

slide-55
SLIDE 55

@anubhavm 

slide-56
SLIDE 56

@anubhavm 

Service Configuration

Hierarchical Key/Value Store HTTP API Long-polling / Edge trigger Locking

slide-57
SLIDE 57

Exercises

slide-58
SLIDE 58

@anubhavm 

Workstations

Claim your workstation! https://hashi.co/velocity-new-york

slide-59
SLIDE 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

slide-60
SLIDE 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>

slide-61
SLIDE 61

WA R N I N G

You are sharing a cluster

Let’s be nice to each other.

slide-62
SLIDE 62

Service Discovery (DNS)

slide-63
SLIDE 63

@anubhavm 

Service Discovery - DNS Interface

Consul's DNS interface is zero touch Randomized Round-Robin DNS Filters on Health Checks

slide-64
SLIDE 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

slide-65
SLIDE 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

slide-66
SLIDE 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=" ;; Query time: 1 msec

slide-67
SLIDE 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

slide-68
SLIDE 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.

slide-69
SLIDE 69

{ "service": { "name": "my-service", "tags": ["tag-1", "tag-2"], "port": 1234 } }

C O D E E D I T O R

slide-70
SLIDE 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

slide-71
SLIDE 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

slide-72
SLIDE 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

slide-73
SLIDE 73

Service Discovery (CLI)

slide-74
SLIDE 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

slide-75
SLIDE 75

@anubhavm 

Exercise: Get Help

Run consul catalog -h to see the list of available CLI service discovery commands.

slide-76
SLIDE 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 .....

slide-77
SLIDE 77

@anubhavm 

Exercise: List Services with Tags

List all registered services with their tags using the service discovery CLI.

slide-78
SLIDE 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

slide-79
SLIDE 79

K/V Store

slide-80
SLIDE 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

slide-81
SLIDE 81

@anubhavm 

K/V Store: Use Cases

Runtime configuration data Secrets or sensitive application data (eg. Vault’s encrypted data)

slide-82
SLIDE 82

@anubhavm 

K/V Store: Use Cases

Runtime configuration data Secrets or sensitive application data (eg. Vault’s encrypted data)

slide-83
SLIDE 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

slide-84
SLIDE 84

T E R M I N A L

$ consul kv get <KEY> <DATA> $ curl http://localhost:8500/v1/kv/<KEY>

slide-85
SLIDE 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.

slide-86
SLIDE 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

slide-87
SLIDE 87

Consul Template

slide-88
SLIDE 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

slide-89
SLIDE 89

@anubhavm 

Consul Template: Architecture

{{ key “hello/world“ }}

CONSUL TEMPLATE

CONSUL

value

FILE

1 2 3

slide-90
SLIDE 90

@anubhavm 

Exercise: Validate Consul Template

Validate Consul Template is installed and configured.

slide-91
SLIDE 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

slide-92
SLIDE 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.

slide-93
SLIDE 93

{{ range service “consul" }} {{ .Address }} {{ end }}

C O D E E D I T O R

slide-94
SLIDE 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

slide-95
SLIDE 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

slide-96
SLIDE 96

@anubhavm 

“Smart Nginx”

server { listen 5051; server { listen 5050; .....

NGINX

slide-97
SLIDE 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

slide-98
SLIDE 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

slide-99
SLIDE 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

slide-100
SLIDE 100

@anubhavm 

Exercise: Validate NGINX

Validate NGINX is installed and configured.

slide-101
SLIDE 101

T E R M I N A L

$ nginx -v nginx version: nginx/1.10.3 (Ubuntu)

slide-102
SLIDE 102

@anubhavm 

Exercise Goal

{{ key “hello/world“ }}

CONSUL TEMPLATE

CONSUL

server { .....

NGINX

SERVICE

slide-103
SLIDE 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

slide-104
SLIDE 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

slide-105
SLIDE 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.

slide-106
SLIDE 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/

slide-107
SLIDE 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

slide-108
SLIDE 108

T E R M I N A L

$ consul reload Configuration reload triggered $ dig $(identity).counting.service.consul

slide-109
SLIDE 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.

slide-110
SLIDE 110

T E R M I N A L

$ cd /workstation/consul/nginx $ vim nginx.conf.tpl

slide-111
SLIDE 111

T E R M I N A L

$ consul-template -template=nginx.conf.tpl -dry

slide-112
SLIDE 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

slide-113
SLIDE 113

T E R M I N A L

$ consul-template -template=nginx.conf.tpl -dry

slide-114
SLIDE 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.

slide-115
SLIDE 115

T E R M I N A L

$ sudo vim /etc/consul.d/templates/nginx-smart-router.json

slide-116
SLIDE 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

slide-117
SLIDE 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

slide-118
SLIDE 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

slide-119
SLIDE 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

slide-120
SLIDE 120

T E R M I N A L

$ sudo systemctl daemon-reload $ sudo service consul-template start

slide-121
SLIDE 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

slide-122
SLIDE 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

slide-123
SLIDE 123

T E R M I N A L

$ curl http://localhost:5050/service/counting/ {“count":1,"hostname":"velocity-badger.node.consul"}

slide-124
SLIDE 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/

slide-125
SLIDE 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.

slide-126
SLIDE 126

T E R M I N A L

$ vim /etc/systemd/system/dashboard.service

slide-127
SLIDE 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

slide-128
SLIDE 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

slide-129
SLIDE 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

slide-130
SLIDE 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

slide-131
SLIDE 131

T E R M I N A L

$ sudo service dashboard start $ consul reload

slide-132
SLIDE 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

slide-133
SLIDE 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.

slide-134
SLIDE 134

T E R M I N A L

$ while true;do curl -i http://localhost:5050/service/counting/;sleep 0.5;done

slide-135
SLIDE 135

T E R M I N A L

$ consul kv put config/global/router/prefer-local-routing 1

slide-136
SLIDE 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.

slide-137
SLIDE 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.

slide-138
SLIDE 138

Fabio

slide-139
SLIDE 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/

slide-140
SLIDE 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.

slide-141
SLIDE 141

T E R M I N A L

$ cd /workstation/nomad $ vim counting-service.nomad

slide-142
SLIDE 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

slide-143
SLIDE 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

slide-144
SLIDE 144

T E R M I N A L

$ nomad run counting-service.nomad $ nomad status counting-service

slide-145
SLIDE 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


slide-146
SLIDE 146

@anubhavm 

Fabio: A Consul Load Balancer

Fabio feels like a “global” load balancer since it spans both, VMs and Containers!

slide-147
SLIDE 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

slide-148
SLIDE 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

slide-149
SLIDE 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!

slide-150
SLIDE 150

Consul Connect

slide-151
SLIDE 151

@anubhavm 

Consul Connect

Service Access Graph Certificate Distribution Application Integration

slide-152
SLIDE 152

@anubhavm 

Service Access Graph

Intentions to Allow/Deny Communication Source and Destination Service Scale Independent Managed with CLI, API, UI, Terraform

slide-153
SLIDE 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)

slide-154
SLIDE 154

@anubhavm 

slide-155
SLIDE 155

@anubhavm 

Certificate Distribution

Transport Layer Security (TLS) Service Identity Encryption of all traffjc

slide-156
SLIDE 156

@anubhavm 

Certificate Format

X.509 Certificate SPIFFE Compatible

slide-157
SLIDE 157

@anubhavm 

Application Integration

Consul Client for Service Graph and Certificates Sidecar Proxies Native Integrations

slide-158
SLIDE 158

@anubhavm 

Sidecar Proxy Integration

No Code Modification Minimal Performance Overhead Operational Flexibility

slide-159
SLIDE 159

@anubhavm 

Sidecar Proxies

Client Proxy App

Configure Connect

Proxy Client App

Configure Connect

slide-160
SLIDE 160

@anubhavm 

Pluggable Proxies

Client App

Configure Connect

Client App

Configure Connect

slide-161
SLIDE 161

@anubhavm 

Pluggable Proxies

Client App

Configure Connect

Client App

Configure Connect Coming soon!

slide-162
SLIDE 162

{ "service": "web", "connect": { "proxy": { "config": { "upstreams": [{ "destination_name": "redis", "local_bind_port": 1234 }] } } } }

C O D E E D I T O R

slide-163
SLIDE 163

@anubhavm 

Proxy Client App

Configure Connect localhost:1234 Connect to upstream redis

slide-164
SLIDE 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 >

slide-165
SLIDE 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

slide-166
SLIDE 166

@anubhavm 

Exercise: Connect Two Service via Consul Connect

Edit the dashboard and counting Consul service files to enable connect.

slide-167
SLIDE 167

T E R M I N A L

$ sudo vim /etc/consul.d/counting.json

slide-168
SLIDE 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

slide-169
SLIDE 169

T E R M I N A L

$ sudo vim /etc/consul.d/dashboard.json

slide-170
SLIDE 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

slide-171
SLIDE 171

@anubhavm 

Exercise: Connect Two Service via Consul Connect

Edit the dashboard systemd config file to point to the local_bind_port 9003.

slide-172
SLIDE 172

T E R M I N A L

$ vim /etc/systemd/system/dashboard.service

slide-173
SLIDE 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

slide-174
SLIDE 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

slide-175
SLIDE 175

@anubhavm 

Exercise: Connect Two Service via Consul Connect

Reload Consul. Restart dashboard service.

slide-176
SLIDE 176

T E R M I N A L

$ consul reload Configuration reload triggered $ sudo systemctl daemon-reload $ sudo service dashboard restart

slide-177
SLIDE 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.

slide-178
SLIDE 178

T E R M I N A L

$ open http://consul.hashicorp.live

slide-179
SLIDE 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

slide-180
SLIDE 180

@anubhavm 

Exercise: Use “Intentions” to Deny All Access

Use the Consul UI to deny all access to all services.

slide-181
SLIDE 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

slide-182
SLIDE 182

T E R M I N A L

$ sudo apt-get install -y redis-tools $ redis-cli -h

slide-183
SLIDE 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.

slide-184
SLIDE 184

T E R M I N A L

$ consul connect proxy \

  • service web \
  • upstream redis-db:6379 &

$ redis-cli

slide-185
SLIDE 185

@anubhavm 

Data Planes for L4

Encrypted Connections to Databases (TCP) Proxy Masquerading

slide-186
SLIDE 186

@anubhavm 

Native Integration

Standard TLS Negligible Performance Overhead Requires Code Modification

slide-187
SLIDE 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

slide-188
SLIDE 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

slide-189
SLIDE 189

@anubhavm 

Consul Connect Lambda Integration

SERVER

Internal Loadbalancer

SERVER SERVER LB App App App App

VPC

Lambda Function SDK API GATEWAY

Internet

slide-190
SLIDE 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

slide-191
SLIDE 191

Demo

slide-192
SLIDE 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.

slide-193
SLIDE 193

Conclusion

slide-194
SLIDE 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.

slide-195
SLIDE 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

slide-196
SLIDE 196

Thanks! I have stickers!

Consul: https://consul.io @anubhavm