define an url for an application inside kubernetes

11/30/2018

hy folks

Currently i trying to setup an url in my kubernetes

I wrote a service to be able to connect to the dns to resolv all external URL. I defined as well an Ingress

kind: Ingress
metadata:
  name: dnsingressresource
spec:
#  tls:
#   - hosts:
#    - < domain>
#     secretName: <tls_secret_name> 
  rules:
  - host: cloud.devlan.xx.xxx
    http:
      paths:
      - path: /mobdev1/auth
        backend:
          serviceName: service-cas-nodeport
          servicePort: 2488

if i want to go to the url of my application i've to write this

https://cloud.devlan.xx.xxx:2488/mobdev1/auth/login

I trying to get this

https://cloud.devlan.xx.xxx/mobdev1/auth/login

do you know how i can get it ?

-- morla
google-kubernetes-engine
kubernetes
kubernetes-ingress

1 Answer

11/30/2018

You should specify port 80 for your Service and targetPort should be the port in your container

Defining a Service

deployment.yaml

kind: Deployment
...
    spec:
      containers:
        - name: my-app
          image: "my-image:my-tag"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 2488
              protocol: TCP

service.yaml

apiVersion: v1
kind: Service
...
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 2488
      protocol: TCP
      name: http

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
...
spec:
  backend:
    serviceName: my-service
    servicePort: 80
-- edbighead
Source: StackOverflow