Skip to content

Instantly share code, notes, and snippets.

@kszarek
Created March 28, 2019 12:14
Show Gist options
  • Save kszarek/5d2a646c6a65598dc5488497a71e6fd9 to your computer and use it in GitHub Desktop.
Save kszarek/5d2a646c6a65598dc5488497a71e6fd9 to your computer and use it in GitHub Desktop.
Consul Sidecar
apiVersion: v1
kind: ConfigMap
metadata:
name: generic
data:
AWS_REGION: eu-west-1
ENVIRONMENT: staging
---
apiVersion: v1
kind: ConfigMap
metadata:
name: consul-config
labels:
app: prometheus
data:
consul.json: |
{
"service": {
"port": 9090,
"address": "6.6.6.6",
"tags": [
"web",
"gcp"
],
"name": "prometheus"
}
}
apiVersion: apps/v1
kind: Deployment
metadata:
name: consul
spec:
selector:
matchLabels:
app: prometheus
component: client
strategy:
type: Recreate
replicas: 1
template:
metadata:
labels:
app: prometheus
component: client
spec:
terminationGracePeriodSeconds: 10
securityContext:
fsGroup: 1000
containers:
- name: consul
image: consul:0.8.0
command:
- "/bin/sh"
- "-ec"
- |
mkdir -p /etc/consul/conf.d/
sed "s/6.6.6.6/$(POD_IP)/" /opt/consul/config/consul.json >/etc/consul/conf.d/prometheus.json
exec /bin/consul agent \
-advertise=$(POD_IP) \
-bind=0.0.0.0 \
-client=0.0.0.0 \
-datacenter=eu-west-1-$(ENVIRONMENT) \
-domain=ahinternal.net \
-join=consul1-$(ENVIRONMENT).ahinternal.net \
-join=consul2-$(ENVIRONMENT).ahinternal.net \
-join=consul3-$(ENVIRONMENT).ahinternal.net \
-retry-join=consul1-$(ENVIRONMENT).ahinternal.net \
-retry-join=consul2-$(ENVIRONMENT).ahinternal.net \
-retry-join=consul3-$(ENVIRONMENT).ahinternal.net \
-log-level=INFO \
-node=$(POD_NAME) \
-data-dir=/var/lib/consul
-config-dir=/etc/consul/conf.d/
ports:
- containerPort: 8301
- containerPort: 8500
- containerPort: 8600
- containerPort: 8301
protocol: "UDP"
envFrom:
- configMapRef:
name: generic
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: consul-config
mountPath: /opt/consul/config
- name: consul-data
mountPath: /var/lib/consul
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- consul leave
volumes:
- name: consul-config
configMap:
name: consul-config
- name: consul-data
emptyDir:
sizeLimit: 128Mi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment