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
# kubectl exec -ti mongo-0 mongo | |
# rs.initiate() | |
# rs.conf() | |
# mongo mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo:27017/test | |
# | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: mongo | |
labels: | |
name: mongo | |
spec: | |
ports: | |
- port: 27017 | |
targetPort: 27017 | |
type: LoadBalancer | |
selector: | |
role: mongo | |
--- | |
apiVersion: apps/v1beta1 | |
kind: StatefulSet | |
metadata: | |
name: mongo | |
spec: | |
serviceName: "mongo" | |
replicas: 3 | |
template: | |
metadata: | |
labels: | |
role: mongo | |
environment: test | |
spec: | |
terminationGracePeriodSeconds: 10 | |
containers: | |
- name: mongo | |
image: mongo:3.4 | |
ports: | |
- containerPort: 27017 | |
volumeMounts: | |
- name: mongo-persistent-storage | |
mountPath: /data/db | |
volumeClaimTemplates: | |
- metadata: | |
name: mongo-persistent-storage | |
annotations: | |
volume.beta.kubernetes.io/storage-class: "fast" | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
resources: | |
requests: | |
storage: 2Gi |
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
# 和google qwlke範例差在 command 和 image/ mongo 3.4版 | |
# kubectl exec -ti mongo-0 mongo | |
# rs.initiate() | |
# rs.conf() | |
# mongo mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo:27017/test | |
# | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: mongo | |
labels: | |
name: mongo | |
spec: | |
ports: | |
- port: 27017 | |
targetPort: 27017 | |
clusterIP: None | |
selector: | |
role: mongo | |
--- | |
apiVersion: apps/v1beta1 | |
kind: StatefulSet | |
metadata: | |
name: mongo | |
spec: | |
serviceName: "mongo" | |
replicas: 3 | |
template: | |
metadata: | |
labels: | |
role: mongo | |
environment: test | |
spec: | |
terminationGracePeriodSeconds: 10 | |
containers: | |
- name: mongo | |
image: mongo:3.4 | |
command: | |
- mongod | |
- "--replSet" | |
- rs0 | |
- "--bind_ip" | |
- 0.0.0.0 | |
- "--smallfiles" | |
- "--noprealloc" | |
ports: | |
- containerPort: 27017 | |
volumeMounts: | |
- name: mongo-persistent-storage | |
mountPath: /data/db | |
- name: mongo-sidecar | |
image: cvallance/mongo-k8s-sidecar | |
env: | |
- name: MONGO_SIDECAR_POD_LABELS | |
value: "role=mongo,environment=test" | |
volumeClaimTemplates: | |
- metadata: | |
name: mongo-persistent-storage | |
annotations: | |
volume.beta.kubernetes.io/storage-class: "fast" | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
resources: | |
requests: | |
storage: 2Gi |