I have an app which will start a server at 127.0.0.1:8080
and using a Dockerfile
to create an image for hosting it on GKE. I deployed this app on port 8080
on the kubernetes cluster. Then I EXPOSE the service as LoadBalancer
for the same port 8080 but it is not allowing it to be accessed from outside. So I created an ingress for external access but still doesn't work.
When I click at the IP provided by ingress, I get this Error:
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.
I would like to ask is there something I have missed or done wrong in the implementation.
My YAML file:
---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "app"
namespace: "default"
labels:
app: "app"
spec:
replicas: 3
selector:
matchLabels:
app: "app"
template:
metadata:
labels:
app: "app"
spec:
containers:
- name: "app-sha256-1"
image: "gcr.io/project-1234/github.com/user/app@sha256:b17b8159668d44fec3d"
---
apiVersion: "autoscaling/v2beta1"
kind: "HorizontalPodAutoscaler"
metadata:
name: "app-hpa-y3ay"
namespace: "default"
labels:
app: "app"
spec:
scaleTargetRef:
kind: "Deployment"
name: "app"
apiVersion: "apps/v1"
minReplicas: 1
maxReplicas: 5
metrics:
- type: "Resource"
resource:
name: "cpu"
targetAverageUtilization: 80
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "app-service"
namespace: "default"
labels:
app: "app"
spec:
ports:
- protocol: "TCP"
port: 8080
selector:
app: "app"
type: "LoadBalancer"
loadBalancerIP: ""
---
apiVersion: "extensions/v1beta1"
kind: "Ingress"
metadata:
name: "ingress"
namespace: "default"
spec:
backend:
serviceName: "app-service"
servicePort: 8080
Thanks! Look forward to the suggestions.
CodePudding user response:
start a server at 127.0.0.1:8080
this would allow your app to accept connection within the pod only. Bind to 0.0.0.0
instead.
Also your Deployment:
...
containers:
- name: "app-sha256-1"
image: "gcr.io/project-1234/github.com/user/app@sha256:b17b8159668d44fec3d"
ports:
- containerPort: <the port# that your container serves>
And your Service:
...
ports:
- protocol: "TCP"
port: 8080
targetPort: <the port that your container serves>