k8s安裝mongo?
vi mongodb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: asmongo
name: mongodb
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
nodeName: k8s-node1 # 固定在 k8s-node1 節點
containers:
- name: mongodb
image: mongo:4.2.9
resources:
limits: # 限定資源
cpu: 2000m
memory: 8Gi
requests:
cpu: 100m
memory: 8Gi
env:
- name: MONGO_INITDB_ROOT_USERNAME # 設置用戶名
value: root
- name: MONGO_INITDB_ROOT_PASSWORD # 設置密碼
value: 'root@123'
volumeMounts:
- mountPath: /data/db
name: mongodb-volume
volumes:
- name: mongodb-volume
hostPath: path: /data/mongodb-volume # 映射的宿主機目錄
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
namespace: asmongo
name: mongodb
spec:
type: ClusterIP
selector:
app: mongodb
ports:
- port: 27018
targetPort: 27018