Skip to content

Instantly share code, notes, and snippets.

@thkoch2001
Last active December 19, 2018 15:14
Show Gist options
  • Save thkoch2001/e37216d1a957b92d04f5f4b28b5d805e to your computer and use it in GitHub Desktop.
Save thkoch2001/e37216d1a957b92d04f5f4b28b5d805e to your computer and use it in GitHub Desktop.
create multiple similar kubernetes deployments and services
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-$SHARD
spec:
selector:
matchLabels:
app: nginx-$SHARD
replicas: 250
template:
metadata:
labels:
app: nginx-$SHARD
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
resources:
requests:
cpu: 10m
#!/bin/sh
# envsubst is in Debian package gettext-base
set -e
SHARDS="a b c d e f g h i j"
export PORT=31000
export SHARD
rm -f deployments.yaml services.yaml
for SHARD in $SHARDS
do
echo $SEPARATOR >> deployments.yaml
echo $SEPARATOR >> services.yaml
SEPARATOR="---"
cat deployment.yaml.in | envsubst >> deployments.yaml
cat service.yaml.in | envsubst >> services.yaml
PORT=$(expr 1 + $PORT)
done
kind: Service
apiVersion: v1
metadata:
name: service-$SHARD
spec:
selector:
app: nginx-$SHARD
ports:
- protocol: TCP
port: 80
nodePort: $PORT
targetPort: 80
type: NodePort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment