diff --git a/K8-Manifest.md b/K8-Manifest.md new file mode 100644 index 0000000..82fc177 --- /dev/null +++ b/K8-Manifest.md @@ -0,0 +1,174 @@ +```yaml +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: mongo-pv +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + hostPath: + path: /home/ubuntu/mongo/mongo-vol + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mongo-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: mongodb-configmap +data: + db_host: mongodb-service + +--- +apiVersion: v1 +kind: Secret +metadata: + name: mongodb-secret +type: Opaque +data: + username: YWRtaW4= + password: MTIz + +--- +apiVersion: v1 +kind: Secret +metadata: + name: mongo-express-secret +type: Opaque +data: + mduser: YWRtaW4= + mdpass: MTIz + meuser: YWRtaW4= + mepass: MTIz + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongodb + labels: + app: mongodb +spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: mongo + ports: + - containerPort: 27017 + env: + - name: MONGO_INITDB_ROOT_USERNAME + valueFrom: + secretKeyRef: + name: mongodb-secret + key: username + - name: MONGO_INITDB_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mongodb-secret + key: password + volumeMounts: + - name: mongo-data + mountPath: /data/db + volumes: + - name: mongo-data + persistentVolumeClaim: + claimName: mongo-pvc + +--- +apiVersion: v1 +kind: Service +metadata: + name: mongodb-service +spec: + selector: + app: mongodb + ports: + - protocol: TCP + port: 27017 + targetPort: 27017 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongo-express + labels: + app: mongo-express +spec: + replicas: 1 + selector: + matchLabels: + app: mongo-express + template: + metadata: + labels: + app: mongo-express + spec: + containers: + - name: mongo-express + image: mongo-express + ports: + - containerPort: 8081 + env: + - name: ME_CONFIG_BASICAUTH_USERNAME + valueFrom: + secretKeyRef: + name: mongo-express-secret + key: meuser + - name: ME_CONFIG_BASICAUTH_PASSWORD + valueFrom: + secretKeyRef: + name: mongo-express-secret + key: mepass + - name: ME_CONFIG_MONGODB_ADMINUSERNAME + valueFrom: + secretKeyRef: + name: mongodb-secret + key: username + - name: ME_CONFIG_MONGODB_ADMINPASSWORD + valueFrom: + secretKeyRef: + name: mongodb-secret + key: password + - name: ME_CONFIG_MONGODB_SERVER + valueFrom: + configMapKeyRef: + name: mongodb-configmap + key: db_host + +--- +apiVersion: v1 +kind: Service +metadata: + name: mongo-express-service +spec: + selector: + app: mongo-express + type: NodePort + ports: + - protocol: TCP + port: 8081 + targetPort: 8081 + +```