Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.