Reputation: 998
I am trying to create the following:
Deployment
for mongoDeployment
for mongo-expressClusterIp
for mongoClusterIp
for mongo-expressI want to be able to go to xyz.com/admin/auth-db-gui
and see the mongo-express gui.
I am running this on Linux minikube.
When going to xyz.com/admin/auth-db-gui
, I get 503 Service Temporarily Unavailable, however when executing kubectl get pods
, I can see 2 pods running.
I will setup the mapping for xyz.com
in /etc/hosts
manually as this is for only dev purpose
db.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-db-deployment
spec:
selector:
matchLabels:
app: auth-db
template:
metadata:
labels:
app: auth-db
spec:
containers:
- name: auth-db
image: mongo
---
apiVersion: v1
kind: Service
metadata:
name: auth-db-service
spec:
selector:
app: auth-db
ports:
- name: auth-db
protocol: TCP
port: 27017
targetPort: 27017
db-gui
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-db-gui-deployment
spec:
selector:
matchLabels:
app: auth-db-gui
template:
metadata:
labels:
app: auth-db-gui
spec:
containers:
- name: auth-db-gui
image: mongo-express
env:
- name: ME_CONFIG_MONGODB_SERVER
value: auth-db-service
---
apiVersion: v1
kind: Service
metadata:
name: auth-db-gui-service
spec:
selector:
app: auth-db-gui
ports:
- name: auth-db-gui
protocol: TCP
port: 27017
targetPort: 27017
ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: xyz-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: xyz.com
http:
paths:
- path: /admin/auth-db-gui
backend:
serviceName: auth-db-gui-service
servicePort: 8081
Sorry if there is an obvious mistake above.
Upvotes: 0
Views: 846
Reputation: 6853
I notice that in some cases 503 means that ports on configured correctly.
I've tested your ingress, along with the service and the deployment and after correcting the mistake with port in the ingress object it works great:
curl -H "Host: xyz.com" "192.168.49.2/admin/auth-db-gui"
{
"path": "/admin/auth-db-gui",
"headers": {
"host": "xyz.com",
"x-request-id": "ff272df6d729af6c1fb4d5f510de88f4",
"x-real-ip": "192.168.49.1",
"x-forwarded-for": "192.168.49.1",
"x-forwarded-host": "xyz.com",
"x-forwarded-port": "80",
"x-forwarded-proto": "http",
"x-scheme": "http",
"user-agent": "curl/7.52.1",
"accept": "*/*"
},
"method": "GET",
"body": "",
"fresh": false,
"hostname": "xyz.com",
"ip": "192.168.49.1",
"os": {
"hostname": "auth-db-gui-deployment-555c77cf75-fjbf2"
For testing purposes I highly recommend mendhak/http-https-echo
. I swapped the image in your deployed and fix the port. You can test the ingress yourself with the below yaml files:
#ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: xyz-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: xyz.com
http:
paths:
- path: /admin/auth-db-gui
backend:
serviceName: auth-db-gui-service
servicePort: 27017
Notice the how the port are being set. The servicePort
in ingress corresponds to service port
which is 27017. I changed the target port of the service since echo-server works on 80
#sevice.yaml
apiVersion: v1
kind: Service
metadata:
name: auth-db-gui-service
spec:
selector:
app: auth-db-gui
ports:
- name: auth-db-gui
protocol: TCP
port: 27017
targetPort: 80
#deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-db-gui-deployment
spec:
selector:
matchLabels:
app: auth-db-gui
template:
metadata:
labels:
app: auth-db-gui
spec:
containers:
- name: auth-db-gui
image: mendhak/http-https-echo
Please have a look at the docs about services for more examples.
Upvotes: 1