k8s部署mongodb副本高可用集群
以下是一个简化的Kubernetes部署MongoDB副本集的高可用集群的YAML配置示例。这个配置假设你已经有了一个运行的Kubernetes集群,并且你已经创建了必要的服务账号和角色绑定以允许Kubelet访问Docker Hub或其他容器镜像仓库。
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 250Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
spec:
replicas: 3
selector:
matchLabels:
role: mongo
template:
metadata:
labels:
role: mongo
spec:
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: your-username
- name: MONGO_INITDB_ROOT_PASSWORD
value: your-password
args:
- "--replSet"
- "rs0"
resources:
requests:
cpu: "0.5"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
volumes:
- name: mongo-persistent-storage
persistentVolumeClaim:
claimName: mongo-pv-claim
---
apiVersion: v1
kind: Pod
metadata:
name: mongo-init-container
spec:
initContainers:
- name: mongo-init-container
image: mongo
command: ["mongoinit.sh"]
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: your-username
- name: MONGO_INITDB_ROOT_PASSWORD
value: your-password
- name: MONGO_INITDB_REPLICA_SET
value: rs0
resources:
requests:
cpu: "0.5"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
volumes:
- name: mongo-persistent-storage
persistentVolumeClaim:
claimName: mongo-pv-
评论已关闭