Reputation: 1
I created mongoDb replica set by using StateFulSet.yaml and Headless.yaml, I installed metal-lb for creating EXTERNAL-IP and load balancer by using the command:
kubectl expose pod mongo-0 --port 27017 --target-port 27017 --type LoadBalancer
kubectl expose pod mongo-1 --port 27017 --target-port 27017 --type LoadBalancer
kubectl expose pod mongo-2 --port 27017 --target-port 27017 --type LoadBalancer
I installed the metal-lb right like from the guide: installation guide.
and configured Layer 2 configuration: Layer 2 configuration
I get EXTERNAL-IP which provide by metal-lb but I can't connect to this addresses.
Inside the k8s cluster every thing goes well but in my local machine not. I'm using windows, wsl and docker-desktop.
I tried to ping and curl, and use mongosh and mongo compass but there is no response from the ip address.
this is the mongo-statefulset.yaml:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
spec:
selector:
matchLabels:
app: mongo
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
app: mongo
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo
command:
- mongod
- "--bind_ip_all"
- "--replSet"
- rs0
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-volume
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-volume
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 4Gi
this is the mongo-headless.yaml:
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
app: mongo
spec:
ports:
- name: mongo
port: 27017
targetPort: 27017
clusterIP: None
selector:
app: mongo
and this is the metal-lb.yaml:
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: smart-cart-pool
namespace: metallb-system
spec:
addresses:
- 192.168.7.200.200-192.168.7.210
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: example
namespace: metallb-system
Upvotes: -1
Views: 27