0

I have created 2 namespaces which are "ingress-basic" and "wallarm-ingress" now I have applied the deploying file in "ingress-basic" namespace and I want to know whether I can have applied my ingress.yaml file in "wallarm-ingress" namespace and expose the deployment to the internet.

This the deployment yaml file `

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api 
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: newwallarmacr.azurecr.io/api-app:v1
        ports:
        - containerPort: 3333
        
---
apiVersion: v1
kind: Service
metadata:
  name: api
spec:
  type: ClusterIP
  ports:
  - port: 3333
  selector:
    app: api

`

And this is the ingress.yaml file

`

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    kubernetes.io/ingress.class: nginx
    name: api
  namespace: ingress-basic
   
    


spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /one(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 3333
     
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 3333

`

I tried this and this didn't work so I want to know which parts should be added, edited to get this deployment expose to the internet.

1 Answers1

1

By default every workload (pod, endpoints, services) are exposed inside particular namespace. But for your case, you want to access a service hosted in wallarm-ingress via an ingress hosted in ingress-basic. In that case service should be called via this syntax.

{serviceName}.{serviceName-namespace}.svc

So your ingress object should be like this

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    kubernetes.io/ingress.class: nginx
    name: api
  namespace: ingress-basic
   
    


spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /one(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: api.wallarm-ingress.svc
            port:
              number: 3333
     
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: api.wallarm-ingress.svc
            port:
              number: 3333
iamattiq1991
  • 746
  • 9
  • 11