Skip to content

Instantly share code, notes, and snippets.

@mjudeikis
Last active July 14, 2017 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjudeikis/f03bb8cea837bb9ccee53fdb172c796b to your computer and use it in GitHub Desktop.
Save mjudeikis/f03bb8cea837bb9ccee53fdb172c796b to your computer and use it in GitHub Desktop.
consul
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
name: consul
namespace: evoc
spec:
serviceName: consul
replicas: 3
template:
metadata:
name: consul
labels:
app: consul
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
securityContext:
fsGroup: 1000
containers:
- name: consul
image: "consul:v0.6.4"
imagePullPolicy: "Always"
ports:
- name: http
containerPort: 8500
- name: rpc
containerPort: 8400
- name: serflan-tcp
protocol: "TCP"
containerPort: 8301
- name: serflan-udp
protocol: "UDP"
containerPort: 8301
- name: serfwan-tcp
protocol: "TCP"
containerPort: 8302
- name: serfwan-udp
protocol: "UDP"
containerPort: 8302
- name: server
containerPort: 8300
- name: consuldns
containerPort: 8600
resources:
requests:
cpu: 100m
memory: 512Mi
env:
- name: INITIAL_CLUSTER_SIZE
value: "3"
- name: PETSET_NAME
value: "consul"
- name: PETSET_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: datadir
mountPath: /var/lib/consul
command:
- "/bin/sh"
- "-ec"
- |
IP=$(hostname -i)
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
while true; do
echo "Waiting for ${PETSET_NAME}-${i}.${PETSET_NAME} to come up"
ping -W 1 -c 1 ${PETSET_NAME}-${i}.${PETSET_NAME}.${PETSET_NAMESPACE}.svc.cluster.local > /dev/null && break
sleep 1s
done
done
PEERS=""
for i in $(seq 0 $((${INITIAL_CLUSTER_SIZE} - 1))); do
PEERS="${PEERS}${PEERS:+ } -retry-join $(ping -c 1 ${PETSET_NAME}-${i}.${PETSET_NAME}.${PETSET_NAMESPACE}.svc.cluster.local | awk -F'[()]' '/PING/{print $2}')"
done
exec /bin/consul agent \
-data-dir=/var/lib/consul \
-server \
-bootstrap-expect=${INITIAL_CLUSTER_SIZE} \
-bind=0.0.0.0 \
-advertise=${IP} \
${PEERS} \
-client=0.0.0.0
volumeClaimTemplates:
- metadata:
name: datadir
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
# upstream recommended max is 700M
storage: 1Gi
###################
apiVersion: v1
kind: Service
metadata:
name: consul-http
labels:
name: consul-http
spec:
ports:
- name: http
port: 8500
targetPort: 8500
selector:
app: consul
type: LoadBalancer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment