I am new to Kubernetes and currently doing some testing using Virtualbox, in Virtualbox, I have created 2 Kubernetes cluster with 1 Master and 1 worker. One Postgresql being installed a my local PC.
I have a simple MVC app based on mvcmovie from Microsoft but uses Postgresql through a connection string. I have created a docker image of the app, and tested working with Docker Desktop, the container is able to load the page and retrieve data from Postgresql. The build image is uploaded to Docker Hub.
I am able to pull the image using the deployment below
apiVersion: apps/v1
kind: Deployment
metadata:
name: ryur-code
spec:
selector:
matchLabels:
app: ryur-code
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: ryur-code
spec:
containers:
- name: ryur-code
image: ryur/kube_test
ports:
- containerPort: 8080
imagePullSecrets:
- name: regcred
---
kind: Service
apiVersion: v1
metadata:
name: ryur-code
spec:
selector:
app: ryur-code
ports:
- port: 8080
targetPort: 8080
type: NodePort
Services
postgre.yaml
apiVersion: v1
kind: Service
metadata:
name: postgre
spec:
selector:
app: ryur-code
ports:
- name: http
protocol: TCP
port: 5432
targetPort: 5432
externalIPs:
- 192.168.68.107
postgre2.yaml
apiVersion: v1
kind: Service
metadata:
name: postgresql
spec:
clusterIP: None
ports:
- port: 5432
---
apiVersion: v1
kind: Endpoints
metadata:
name: postgresql
subsets:
- addresses:
- ip: 192.168.68.107
ports:
- port: 5432
name: postgresql
I am able load the main page, however, it will give me an “error occurred while processing your request”, if I am trying to access the postgre database.
I have tried with the postgre.yaml and also postgre2.yaml, both not working, also tried a number of services. Again, the postgre DB sits in 192.168.68.107 local DB, is not part of of the Kubernetes cluster.
Note: I have also include all the IPs there is into pg_hba.conf, including ,host all all 0.0.0.0/0 scram-sha-256
from the VM, I am also able to ping the PC localhost where the postgre database is located. No firewall is present.
Honestly stumped if I am doing this correctly, appreciate your help and feedback.
enter image description here
voty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.