Created
September 21, 2021 23:00
-
-
Save hamishforbes/a6a02721d51ca22ea05e35c93cb88242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local k = import 'k.libsonnet'; | |
local container = k.core.v1.container; | |
local containerPort = k.core.v1.containerPort; | |
local deployment = k.apps.v1.deployment; | |
local service = k.core.v1.service; | |
local configMap = k.core.v1.configMap; | |
/* | |
* Create an envoy load balancer for distributors | |
* Prometheus remote write uses a single long-lived connection so the DNS load balancing provided by Consul is a poor fit | |
* Deploy an envoy reverse proxy to round robin between distributors | |
*/ | |
{ | |
_config+:: { | |
distributor_lb: { | |
enabled: true, | |
image: 'envoyproxy/envoy-alpine:v1.19.0', | |
envoy: { | |
static_resources: { | |
listeners: [ | |
{ | |
name: 'listener_0', | |
address: { | |
socket_address: { | |
address: '0.0.0.0', | |
port_value: 10000, | |
}, | |
}, | |
filter_chains: [ | |
{ | |
filters: [ | |
{ | |
name: 'envoy.filters.network.http_connection_manager', | |
typed_config: { | |
'@type': 'type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager', | |
stat_prefix: 'ingress_http', | |
access_log: [ | |
{ | |
name: 'envoy.access_loggers.stdout', | |
typed_config: { | |
'@type': 'type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog', | |
}, | |
}, | |
], | |
http_filters: [ | |
{ name: 'envoy.filters.http.router' }, | |
], | |
route_config: { | |
name: 'local_route', | |
virtual_hosts: [ | |
{ | |
name: 'local_service', | |
domains: ['*'], | |
routes: [ | |
{ | |
match: { | |
prefix: '/', | |
}, | |
route: { | |
cluster: 'distributor_service', | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
], | |
clusters: [ | |
{ | |
name: 'distributor_service', | |
type: 'STRICT_DNS', | |
dns_lookup_family: 'V4_ONLY', | |
lb_policy: 'ROUND_ROBIN', | |
load_assignment: { | |
cluster_name: 'some_service', | |
endpoints: [ | |
{ | |
lb_endpoints: [ | |
{ | |
endpoint: { | |
address: { | |
socket_address: { | |
address: 'distributor.cortex.svc.cluster.local', | |
port_value: 80, | |
}, | |
}, | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
}, | |
], | |
}, | |
}, | |
}, | |
}, | |
distributor_lb+: { | |
config+: | |
configMap.new('distributor-lb') + | |
configMap.withData({ | |
'envoy.yaml': | |
std.manifestYamlDoc($._config.distributor_lb.envoy), | |
}), | |
container+:: | |
container.new('lb', $._config.distributor_lb.image) + | |
container.withPorts([ | |
containerPort.newNamed(name='http', containerPort=10000), | |
]) + | |
$.util.resourcesRequests('100m', '256Mi') + | |
$.util.resourcesLimits(1, '1Gi'), | |
deployment+: | |
deployment.new('distributor-lb', 3, [self.container]) + | |
deployment.spec.template.metadata.withAnnotationsMixin({ | |
'config-hash': std.md5(std.manifestYamlDoc($._config.distributor_lb.envoy)), | |
},) + | |
$.util.antiAffinity + | |
$.util.configVolumeMount(self.config.metadata.name, '/etc/envoy/'), | |
service+: | |
$.util.serviceFor(self.deployment) + | |
service.spec.withClusterIP('None'), | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment