Can't change gateway port on service #1697
-
Hi, I must be missing something, because i am stuck with something that seems simple. I have the following service (from, just changed the http port to apiVersion: v1
kind: Service
metadata:
name: nginx-gateway
namespace: nginx-gateway
labels:
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/instance: nginx-gateway
app.kubernetes.io/version: "1.0.0"
spec:
type: NodePort
selector:
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/instance: nginx-gateway
ports: # Update the following ports to match your Gateway Listener ports
- name: http
port: 8080
protocol: TCP
targetPort: 80
- name: https
port: 443
protocol: TCP
targetPort: 443 Then i create a gateway with a listener on port apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: hello
namespace: default
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 8080
protocol: HTTP I also have a route, which does not seem relevant, listing for sake of completeness: apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: hello
namespace: default
spec:
parentRefs:
- name: hello
hostnames:
- "hello.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: hello-app
port: 3000
Now getting the nodeport of the k -n nginx-gateway get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-gateway NodePort 10.99.245.204 <none> 8080:32516/TCP,443:30640/TCP 36m And then trying to curl: curl -k https://node-1:32516 -H "Host: hello.example.com"
curl: (7) Failed to connect to machine-1 port 32516 after 0 ms: Connection refused
If I change the port on the service and gateway listener back to How can I change the port number as indicated in the comment (and mentioned here: https://docs.nginx.com/nginx-gateway-fabric/installation/expose-nginx-gateway-fabric/) tx., |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @jenwirth, The |
Beta Was this translation helpful? Give feedback.
Hi @jenwirth,
The
targetPort
in your service definition also needs to be changed to 8080. ThetargetPort
is the port on which the service will send requests to. With the current configuration, the service is exposed on port 8080 (mapped to NodePort 32516) but forwards the request to the NGINX Gateway Fabric Pod on port 80.