Can't use an external port in kubernetes with nginx ingress

8/29/2017

I am trying to use port 8888 to load a service, but for some reason only port 80 works, while the site can't be reached with port 8888.

The configuration is as follows:

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  labels:
    k8s-addon: ingress-nginx.addons.k8s.io
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
spec:
  type: LoadBalancer
  selector:
    app: ingress-nginx
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https
  - name: port8888
    port: 8888
    targetPort: 8888

---

kind: ConfigMap
apiVersion: v1
metadata:
  name: ingress-nginx
  labels:
    k8s-addon: ingress-nginx.addons.k8s.io
data:
  use-proxy-protocol: "true"
  8888: "default/some-api:8888"

---

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: ingress-nginx
  labels:
    k8s-addon: ingress-nginx.addons.k8s.io
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: ingress-nginx
        k8s-addon: ingress-nginx.addons.k8s.io
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.11
        name: ingress-nginx
        imagePullPolicy: Always
        ports:
          - name: http
            containerPort: 80
            protocol: TCP
          - name: https
            containerPort: 443
            protocol: TCP
          - name: port8888
            containerPort: 8888
            protocol: TCP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/nginx-default-backend
        - --configmap=$(POD_NAMESPACE)/ingress-nginx
        - --publish-service=$(POD_NAMESPACE)/ingress-nginx

The line 8888: "default/some-api:8888" is in accordance to the ingress example as can be seen here: https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/examples/tcp/tcp-configmap-example.yaml

I also added port 8888 to the list of ports in the Load balancer & the Deployment itself.

The code for the service is:

apiVersion: v1
kind: Service
metadata:
  name: some-api
  labels:
    name: some-api
spec:
  ports:
  - port: 8888
  selector:
    name: some-api

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: some-api-dply
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: some-api
    spec:
      containers:
      - name: some-api-container
        image: [url-ommited]
        ports:
        - containerPort: 8888
          hostPort: 8888

Note: In AWS, in the Load Balancer's Listeners page, the configuration is set to:

LB Protocol | Port | Inst. Protocol | Inst. Port
TCP         | 8888 |      TCP       | 32585

The ingress code looks like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/rewrite-target: /
  name: rewrite
  namespace: default
spec:
  rules:
  - host: "*.elb.amazonaws.com"
    http:
      paths:
      - backend:
          serviceName: some-api
          servicePort: 8888
        path: /
-- Deano
docker-ingress
kubernetes
nginx
ports

0 Answers