☸️
Kubernetes

Go + MongoDB on Kubernetes

Go survey app with MongoDB sidecar — 2 replicas on Minikube/EKS

📋Configuration Files

deployment.yml

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: go-app-deploy
5 namespace: go-survey
6 labels:
7 app: go-app
8spec:
9 selector:
10 matchLabels:
11 app: go-app
12 replicas: 2
13 template:
14 metadata:
15 labels:
16 app: go-app
17 spec:
18 containers:
19 - name: go-app
20 image: your-registry/gosurvey:latest
21 ports:
22 - containerPort: 8080
23 env:
24 - name: MONGODB_URI
25 value: "mongodb://mongo-app-service:27017"
26 - name: SERVER_PORT
27 value: "8080"
28 securityContext:
29 allowPrivilegeEscalation: false
30 - name: mongo-app
31 image: mongo:latest
32 ports:
33 - containerPort: 27017
34 securityContext:
35 allowPrivilegeEscalation: false

service.yml

yaml
1apiVersion: v1
2kind: Service
3metadata:
4 name: go-app-service
5 namespace: go-survey
6spec:
7 type: NodePort
8 selector:
9 app: go-app
10 ports:
11 - port: 8080
12 targetPort: 8080
13 nodePort: 30080
14---
15apiVersion: v1
16kind: Service
17metadata:
18 name: mongo-app-service
19 namespace: go-survey
20spec:
21 selector:
22 app: go-app
23 ports:
24 - port: 27017
25 targetPort: 27017
📄

Step 01

Deploy to Kubernetes

(01)Create namespace and apply

Linux
1kubectl create namespace go-survey
2kubectl apply -f deployment.yml
3kubectl apply -f service.yml
4kubectl -n go-survey get pods,svc
5curl http://localhost:30080 # minikube: minikube service go-app-service -n go-survey