Skip to content

Instantly share code, notes, and snippets.

@riddhi89
Last active May 25, 2022 14:26
Show Gist options
  • Save riddhi89/8a7f2e2ef4956decaf72bfff8a49acfe to your computer and use it in GitHub Desktop.
Save riddhi89/8a7f2e2ef4956decaf72bfff8a49acfe to your computer and use it in GitHub Desktop.
Sample demo
✗ cat catalog_service_register.json
{
"Datacenter": "dc1",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"NodeMeta": {
"somekey": "somevalue"
},
"Service": {
"ID": "redis1-sidecar-proxy",
"Service": "redis1-sidecar-proxy",
"Kind": "connect-proxy",
"Port": 8000,
"Proxy": {
"DestinationServiceName": "redis"
}
},
"Check": {
"CheckID": "health-check1",
"Definition": {
"ScriptArgs": [
"/usr/local/bin/check_redis.py"
],
"Interval": "10s"
}
}
}
✗ cat proxy_defaults.json
{
"Kind": "proxy-defaults",
"Name": "global",
"Mode": "direct",
"Config": {
"local_connect_timeout_ms": 1000,
"handshake_timeout_ms": 10000
}
}
✗ cat service_defaults.json
{
"Kind": "service-defaults",
"Name": "redis",
"Mode": "transparent",
"UpstreamConfig": {
"Defaults": {
"MeshGateway": {
"Mode": "local"
},
"Limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
}
}
}
}
✗ curl --request PUT --data @catalog_service_register.json http://localhost:8500/v1/catalog/register
true
✗ consul config write service_defaults.json
Config entry written: service-defaults/redis
✗ consul config write proxy_defaults.json
Config entry written: proxy-defaults/global
✗ curl -i -X GET http://localhost:8500/v1/catalog/service/redis1-sidecar-proxy
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 29
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:18:48 GMT
Content-Length: 1122
[
{
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"NodeMeta": {
"somekey": "somevalue"
},
"ServiceKind": "connect-proxy",
"ServiceID": "redis1-sidecar-proxy",
"ServiceName": "redis1-sidecar-proxy",
"ServiceTags": [],
"ServiceAddress": "",
"ServiceTaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"ServiceWeights": {
"Passing": 1,
"Warning": 1
},
"ServiceMeta": {},
"ServicePort": 8000,
"ServiceSocketPath": "",
"ServiceEnableTagOverride": false,
"ServiceProxy": {
"DestinationServiceName": "redis",
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"ServiceConnect": {},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
#############
curl -i -X GET http://localhost:8500/v1/catalog/service/redis1-sidecar-proxy\?merge-central-config
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 33
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:17:34 GMT
Content-Length: 1997
[
{
"ID": "",
"Node": "synthetic-node1",
"Address": "",
"Datacenter": "",
"TaggedAddresses": null,
"NodeMeta": null,
"ServiceKind": "connect-proxy",
"ServiceID": "redis1-sidecar-proxy",
"ServiceName": "redis1-sidecar-proxy",
"ServiceTags": [],
"ServiceAddress": "",
"ServiceTaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"ServiceWeights": {
"Passing": 1,
"Warning": 1
},
"ServiceMeta": {},
"ServicePort": 8000,
"ServiceSocketPath": "",
"ServiceEnableTagOverride": false,
"ServiceProxy": {
"DestinationServiceName": "redis",
"Mode": "transparent",
"Config": {
"handshake_timeout_ms": 10000,
"local_connect_timeout_ms": 1000
},
"Upstreams": [
{
"DestinationType": "",
"DestinationNamespace": "default",
"DestinationPartition": "default",
"DestinationName": "*",
"Datacenter": "",
"Config": {
"limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
},
"mesh_gateway": {
"Mode": "local"
}
},
"MeshGateway": {
"Mode": "local"
},
"CentrallyConfigured": true
}
],
"MeshGateway": {},
"Expose": {}
},
"ServiceConnect": {},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
✗ curl -i -X GET http://localhost:8500/v1/catalog/connect/redis
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 29
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:19:53 GMT
Content-Length: 1122
[
{
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"NodeMeta": {
"somekey": "somevalue"
},
"ServiceKind": "connect-proxy",
"ServiceID": "redis1-sidecar-proxy",
"ServiceName": "redis1-sidecar-proxy",
"ServiceTags": [],
"ServiceAddress": "",
"ServiceTaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"ServiceWeights": {
"Passing": 1,
"Warning": 1
},
"ServiceMeta": {},
"ServicePort": 8000,
"ServiceSocketPath": "",
"ServiceEnableTagOverride": false,
"ServiceProxy": {
"DestinationServiceName": "redis",
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"ServiceConnect": {},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
✗ curl -i -X GET http://localhost:8500/v1/catalog/connect/redis\?merge-central-config
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 33
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:20:09 GMT
Content-Length: 1997
[
{
"ID": "",
"Node": "synthetic-node1",
"Address": "",
"Datacenter": "",
"TaggedAddresses": null,
"NodeMeta": null,
"ServiceKind": "connect-proxy",
"ServiceID": "redis1-sidecar-proxy",
"ServiceName": "redis1-sidecar-proxy",
"ServiceTags": [],
"ServiceAddress": "",
"ServiceTaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"ServiceWeights": {
"Passing": 1,
"Warning": 1
},
"ServiceMeta": {},
"ServicePort": 8000,
"ServiceSocketPath": "",
"ServiceEnableTagOverride": false,
"ServiceProxy": {
"DestinationServiceName": "redis",
"Mode": "transparent",
"Config": {
"handshake_timeout_ms": 10000,
"local_connect_timeout_ms": 1000
},
"Upstreams": [
{
"DestinationType": "",
"DestinationNamespace": "default",
"DestinationPartition": "default",
"DestinationName": "*",
"Datacenter": "",
"Config": {
"limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
},
"mesh_gateway": {
"Mode": "local"
}
},
"MeshGateway": {
"Mode": "local"
},
"CentrallyConfigured": true
}
],
"MeshGateway": {},
"Expose": {}
},
"ServiceConnect": {},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
✗ curl -i -X GET http://localhost:8500/v1/health/service/redis1-sidecar-proxy
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 29
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:21:40 GMT
Transfer-Encoding: chunked
[
{
"Node": {
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"Meta": {
"somekey": "somevalue"
},
"CreateIndex": 29,
"ModifyIndex": 29
},
"Service": {
"Kind": "connect-proxy",
"ID": "redis1-sidecar-proxy",
"Service": "redis1-sidecar-proxy",
"Tags": [],
"Address": "",
"TaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"Meta": null,
"Port": 8000,
"Weights": {
"Passing": 1,
"Warning": 1
},
"EnableTagOverride": false,
"Proxy": {
"DestinationServiceName": "redis",
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"Connect": {},
"PeerName": "",
"CreateIndex": 29,
"ModifyIndex": 29
},
"Checks": [
{
"Node": "synthetic-node1",
"CheckID": "health-check1",
"Name": "",
"Status": "critical",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Type": "script",
"Interval": "",
"Timeout": "",
"ExposedPort": 0,
"Definition": {
"Interval": "10s",
"ScriptArgs": [
"/usr/local/bin/check_redis.py"
]
},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
}
]
✗ curl -i -X GET http://localhost:8500/v1/health/service/redis1-sidecar-proxy\?merge-central-config
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 33
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:21:57 GMT
Transfer-Encoding: chunked
[
{
"Node": {
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"Meta": {
"somekey": "somevalue"
},
"CreateIndex": 29,
"ModifyIndex": 29
},
"Service": {
"Kind": "connect-proxy",
"ID": "redis1-sidecar-proxy",
"Service": "redis1-sidecar-proxy",
"Tags": [],
"Address": "",
"TaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"Meta": null,
"Port": 8000,
"Weights": {
"Passing": 1,
"Warning": 1
},
"EnableTagOverride": false,
"Proxy": {
"DestinationServiceName": "redis",
"Mode": "transparent",
"Config": {
"handshake_timeout_ms": 10000,
"local_connect_timeout_ms": 1000
},
"Upstreams": [
{
"DestinationType": "",
"DestinationNamespace": "default",
"DestinationPartition": "default",
"DestinationName": "*",
"Datacenter": "",
"Config": {
"limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
},
"mesh_gateway": {
"Mode": "local"
}
},
"MeshGateway": {
"Mode": "local"
},
"CentrallyConfigured": true
}
],
"MeshGateway": {},
"Expose": {}
},
"Connect": {},
"PeerName": "",
"CreateIndex": 29,
"ModifyIndex": 29
},
"Checks": [
{
"Node": "synthetic-node1",
"CheckID": "health-check1",
"Name": "",
"Status": "critical",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Type": "script",
"Interval": "",
"Timeout": "",
"ExposedPort": 0,
"Definition": {
"Interval": "10s",
"ScriptArgs": [
"/usr/local/bin/check_redis.py"
]
},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
}
]
✗ curl -i -X GET http://localhost:8500/v1/health/connect/redis
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 29
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:22:51 GMT
Transfer-Encoding: chunked
[
{
"Node": {
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"Meta": {
"somekey": "somevalue"
},
"CreateIndex": 29,
"ModifyIndex": 29
},
"Service": {
"Kind": "connect-proxy",
"ID": "redis1-sidecar-proxy",
"Service": "redis1-sidecar-proxy",
"Tags": [],
"Address": "",
"TaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"Meta": null,
"Port": 8000,
"Weights": {
"Passing": 1,
"Warning": 1
},
"EnableTagOverride": false,
"Proxy": {
"DestinationServiceName": "redis",
"Mode": "",
"MeshGateway": {},
"Expose": {}
},
"Connect": {},
"PeerName": "",
"CreateIndex": 29,
"ModifyIndex": 29
},
"Checks": [
{
"Node": "synthetic-node1",
"CheckID": "health-check1",
"Name": "",
"Status": "critical",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Type": "script",
"Interval": "",
"Timeout": "",
"ExposedPort": 0,
"Definition": {
"Interval": "10s",
"ScriptArgs": [
"/usr/local/bin/check_redis.py"
]
},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
}
]
✗ curl -i -X GET http://localhost:8500/v1/health/connect/redis\?merge-central-config
HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
X-Consul-Default-Acl-Policy: allow
X-Consul-Effective-Consistency: leader
X-Consul-Index: 33
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
X-Consul-Query-Backend: blocking-query
Date: Wed, 25 May 2022 14:23:16 GMT
Transfer-Encoding: chunked
[
{
"Node": {
"ID": "",
"Node": "synthetic-node1",
"Address": "127.0.0.1",
"Datacenter": "dc1",
"TaggedAddresses": {
"lan": "127.0.0.1",
"wan": "10.0.10.10"
},
"Meta": {
"somekey": "somevalue"
},
"CreateIndex": 29,
"ModifyIndex": 29
},
"Service": {
"Kind": "connect-proxy",
"ID": "redis1-sidecar-proxy",
"Service": "redis1-sidecar-proxy",
"Tags": [],
"Address": "",
"TaggedAddresses": {
"consul-virtual": {
"Address": "240.0.0.1",
"Port": 8000
}
},
"Meta": null,
"Port": 8000,
"Weights": {
"Passing": 1,
"Warning": 1
},
"EnableTagOverride": false,
"Proxy": {
"DestinationServiceName": "redis",
"Mode": "transparent",
"Config": {
"handshake_timeout_ms": 10000,
"local_connect_timeout_ms": 1000
},
"Upstreams": [
{
"DestinationType": "",
"DestinationNamespace": "default",
"DestinationPartition": "default",
"DestinationName": "*",
"Datacenter": "",
"Config": {
"limits": {
"MaxConnections": 512,
"MaxPendingRequests": 512,
"MaxConcurrentRequests": 512
},
"mesh_gateway": {
"Mode": "local"
}
},
"MeshGateway": {
"Mode": "local"
},
"CentrallyConfigured": true
}
],
"MeshGateway": {},
"Expose": {}
},
"Connect": {},
"PeerName": "",
"CreateIndex": 29,
"ModifyIndex": 29
},
"Checks": [
{
"Node": "synthetic-node1",
"CheckID": "health-check1",
"Name": "",
"Status": "critical",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": "",
"ServiceTags": [],
"Type": "script",
"Interval": "",
"Timeout": "",
"ExposedPort": 0,
"Definition": {
"Interval": "10s",
"ScriptArgs": [
"/usr/local/bin/check_redis.py"
]
},
"CreateIndex": 29,
"ModifyIndex": 29
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment