I setup a postgreSQL with istio injected in K8s, and I want to use psql(or a postgreSQL client) to access it from other network so I am tryinng to setup istio-ingressgateway to access it, and setup the related gateway and virtualservice to route the traffic, but get some errors as below. Please help take a look the issue.
"psql: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. "
yaml files as below
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
labels:
app: postgres
data:
POSTGRES_DB: usermgt
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin2020
EOF
cat <<EOF | kubectl apply -f -
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pv-claim
labels:
app: postgres
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
EOF
cat <<EOF | istioctl kube-inject -f - | kubectl apply -f -
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:10.4
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: postgres-config
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgredb
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
ports:
- port: 5432
selector:
app: postgres
EOF
cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: postgres-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 5432
name: pgsql
protocol: TCP
hosts:
- "*"
EOF
cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: psql-vs
spec:
hosts:
- "*"
gateways:
- postgres-gateway
tcp:
- match:
- port: 5432
route:
- destination:
host: postgres.default
port:
number: 5432
EOF