Skip to content

Instantly share code, notes, and snippets.

@jperville
Created January 9, 2017 11:16
Show Gist options
  • Save jperville/faab63ab3704e5f2161c0feb81e82f06 to your computer and use it in GitHub Desktop.
Save jperville/faab63ab3704e5f2161c0feb81e82f06 to your computer and use it in GitHub Desktop.
Petset example to deploy mongodb 3.2
kind: Template
apiVersion: v1
metadata:
name: mongodb-petset-replication
annotations:
description: "MongoDB Replication (based on PetSet). You must have persistent volumes available in your cluster to use this template."
iconClass: "icon-mongodb"
tags: "database,mongodb,replication"
parameters:
- name: MONGODB_USER
displayName: "MongoDB Connection Username"
description: "Username for MongoDB user that will be used for accessing the database."
generate: expression
from: "[a-zA-Z0-9]{3}"
required: true
- name: MONGODB_PASSWORD
displayName: "MongoDB Connection Password"
description: "Password for the MongoDB connection user."
generate: expression
from: "[a-zA-Z0-9]{16}"
required: true
- name: MONGODB_DATABASE
displayName: "MongoDB Database Name"
description: "Name of the MongoDB database accessed."
value: sampledb
required: true
- name: MONGODB_ADMIN_PASSWORD
displayName: "MongoDB Admin Password"
description: "Password for the database admin user."
generate: expression
from: "[a-zA-Z0-9]{16}"
required: true
- name: MONGODB_REPLICA_NAME
displayName: "Replica Set Name"
description: "The name of the replica set."
value: rs0
required: true
- name: MONGODB_KEYFILE_VALUE
displayName: "Keyfile Content"
description: "The value of the MongoDB keyfile (https://docs.mongodb.com/manual/core/security-internal-authentication/#internal-auth-keyfile)."
generate: expression
from: "[a-zA-Z0-9]{255}"
required: true
- name: MONGODB_IMAGE
displayName: "MongoDB Docker Image"
description: "A reference to a supported MongoDB Docker image."
value: "centos/mongodb-32-centos7"
required: true
- name: MONGODB_SERVICE_NAME
displayName: "OpenShift Service Name"
description: "The name of the OpenShift Service exposed for the database."
value: mongodb
required: true
- name: MEMORY_LIMIT
displayName: "Memory Limit"
description: "Maximum amount of memory the container can use."
value: "512Mi"
objects:
# A headless service to create DNS records
- kind: Service
apiVersion: v1
metadata:
name: "${MONGODB_SERVICE_NAME}"
annotations:
# workaround for https://github.com/kubernetes/kubernetes/issues/39363
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
clusterIP: None
# the list of ports that are exposed by this service
ports:
- name: mongodb
port: 27017
# will route traffic to pods having labels matching this selector
selector:
name: "${MONGODB_SERVICE_NAME}"
- kind: PetSet
apiVersion: apps/v1alpha1
metadata:
name: "${MONGODB_SERVICE_NAME}"
spec:
# pets get DNS/hostnames that follow the pattern: ${metadata.name}-NUM.${spec.serviceName}.default.svc.cluster.local
serviceName: "${MONGODB_SERVICE_NAME}"
replicas: 5
# describes the pod that will be created if insufficient replicas are detected
template:
metadata:
# this label will be used for count running pods
labels:
name: "${MONGODB_SERVICE_NAME}"
annotations:
# 'false' pauses a petset after creation of each pet, to avoid it we set it to 'true'
pod.alpha.kubernetes.io/initialized: "true"
spec:
containers:
- name: mongo-container
image: "${MONGODB_IMAGE}"
ports:
- containerPort: 27017
args:
- "run-mongod-pet"
livenessProbe:
exec:
command:
- "scl"
- "enable"
- "rh-mongodb32"
- "--"
- "mongo"
- "--eval"
- "db.adminCommand('ping')"
initialDelaySeconds: 30
timeoutSeconds: 5
readinessProbe:
exec:
command:
- "scl"
- "enable"
- "rh-mongodb32"
- "--"
- "mongo"
- "--eval"
- "db.adminCommand('ping')"
initialDelaySeconds: 5
timeoutSeconds: 1
volumeMounts:
- name: mongo-data
mountPath: "/var/lib/mongodb/data"
env:
- name: MONGODB_USER
value: "${MONGODB_USER}"
- name: MONGODB_PASSWORD
value: "${MONGODB_PASSWORD}"
- name: MONGODB_DATABASE
value: "${MONGODB_DATABASE}"
- name: MONGODB_ADMIN_PASSWORD
value: "${MONGODB_ADMIN_PASSWORD}"
- name: MONGODB_REPLICA_NAME
value: "${MONGODB_REPLICA_NAME}"
- name: MONGODB_KEYFILE_VALUE
value: "${MONGODB_KEYFILE_VALUE}"
- name: MONGODB_SERVICE_NAME
value: "${MONGODB_SERVICE_NAME}"
resources:
limits:
memory: "${MEMORY_LIMIT}"
volumes:
- name: mongo-data
emptyDir: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment