Last active
December 19, 2018 15:14
-
-
Save thkoch2001/e37216d1a957b92d04f5f4b28b5d805e to your computer and use it in GitHub Desktop.
create multiple similar kubernetes deployments and services
This file contains 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
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 |
This file contains 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
#!/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 |
This file contains 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
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