k8s快速创建MongoDB
1.创建MongoDB pvc文件
如果不需要持久存储可以忽略
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mongodb-data
namespace: t1-zdbl
spec:
storageClassName: nfs-client #这里使用的存储类
accessModes:
- ReadWriteMany
resources:
requests:
storage: 30G
2.创建deployment文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: t1-zdbl-mongodb
namespace: t1-zdbl
spec:
replicas: 1
selector:
matchLabels:
app: t1-zdbl-mongodb
template:
metadata:
labels:
app: t1-zdbl-mongodb
spec:
containers:
- name: zdbl-mongodb
image: mongo:4.4.15
env:
- name: MONGO_INITDB_ROOT_USERNAME #注意我设置了用户名和密码
value: root
- name: MONGO_INITDB_ROOT_PASSWORD
value: 'qiD303d1Q$8Yq^Sj'
ports:
- containerPort: 27017
volumeMounts:
- name: mongodb-data
mountPath: /data/db
volumes:
- name: mongodb-data
persistentVolumeClaim:
claimName: mongodb-data
3.创建svc文件
apiVersion: v1
kind: Service
metadata:
labels:
app: t1-zdbl-mongodb
name: t1-zdbl-mongodb
namespace: t1-zdbl
spec:
type: NodePort
ports:
- name: mongo
port: 27017
protocol: TCP
targetPort: 27017
selector:
app: t1-zdbl-mongodb
应用以上文件即可
"一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少