4

I'm pretty new to K8s.

I'm trying to make my app visible to the outside world. I have deployed this Nginx Ingress Controller with my apps, using Helm and helmfile which has given me an external ip address and a load balancer.

As I understand it, I now need an ingress resource to configure the route mappings.

I plan on using this ingress resource as a starting point.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80

My apps are deployed in separate namespaces on port 80.

My question is: where do I put the yaml for creating the resources?

I want to keep everything in Helm if possible to make managing the configuration easier, so I don't want to use kubectl unless i have to.

My helmfile

repositories:
 
- name: stable
  url: https://charts.helm.sh/stable
- name: nginx-stable
  url: https://helm.nginx.com/stable

releases:

  # other apps configured here

  - name: ingress-nginx
    namespace: ingress
    createNamespace: true
    chart: nginx-stable/nginx-ingress
    values:
      - ./ingress/values.yaml
    version: 0.10.4
    installed: true 

My Ingress Controller values.yaml:

---
rbac:
  create: true

serviceAccount:
  create: true
  name: nginx-ingress-public

controller:
  ingressClassResource:
    enabled: true
    default: true

  replicaCount: 3
  minAvailable: 3
  updateStrategy:
    rollingUpdate:
      maxSurge: 3
      maxUnavailable: 0
WhatTheWhat
  • 197
  • 3
  • 13

1 Answers1

6

You should deploy the ingress controller only once as it can handle all ingress traffic for your whole cluster.

Sometimes it makes sense to deploy multiple, for example we run 2 ingress controller. 1 for internal traffic (private IP) and one for external traffic (public IP).

Once you have that, you just tell your other helm releases to use its ingress class.

The ingress manifest is usually a template of your helm chart. So you put it in templates. If you do helm create my-app, you get a good starting point, including ingress.

Once you have an ingress template in your chart, you can add some reasonable defaults for this template to the values.yaml of the chart, as usual.

When deploying the chart, you can use certain flags to override the defaults. i.e. -f and --set.

The Fool
  • 16,715
  • 5
  • 52
  • 86
  • Hi, thanks for your response. I have used `helm create my-app` and can see the ingress file, however it looks very "templatey". Can I just hardcode the values in there, or does it pick up the values from somewhere else (I appreciate this has turned into a "how do templates work" question. For example, can i put the values in the helmfile, to pass to the chart... to pass to the ingress.yaml file. – WhatTheWhat May 15 '22 at 09:06
  • 1
    @WhatTheWhat, I am assuming that your app is already deployed via helm chart. Maybe this helps https://helm.sh/docs/topics/charts/ – The Fool May 15 '22 at 10:45
  • yes it is, deployed and works fine. I can access it locally using port forwarding. I use helmfile to sync local changes to the cluster. Sorry but i don't see how the link helps, I still can't see where I put the ingress resource values – WhatTheWhat May 15 '22 at 10:51
  • according to this: https://helm.sh/docs/chart_template_guide/values_files i can put them directly in the `values.yaml` for the ingress template to pick up? – WhatTheWhat May 15 '22 at 10:54
  • 2
    @WhatTheWhat, yes, the values files is there to set the default values used by the templates in your templates directory. You can override these with the -f or --set flags when installing the chart. – The Fool May 15 '22 at 10:57
  • If you want to include that in your answer, I'll mark it as solved. – WhatTheWhat May 15 '22 at 10:59
  • 1
    @WhatTheWhat, I have added this info. – The Fool May 15 '22 at 11:07
  • One thing that i'm not clear on: if i define ingress values (ingress resource) for one of my apps, does that apply to other apps? For example, I want to route everything on `/` to a specific app. If i define that in one app, how does the other app know about it? – WhatTheWhat May 16 '22 at 10:21
  • also i can't find `ingressClassName` in the template file. This seems really hard! – WhatTheWhat May 16 '22 at 11:10
  • 1
    @WhatTheWhat, its a template. You can adjust it to your needs. For example adding the ingressClassName key. Regarding your question about routing, the apps dont know about each other but your ingress controller does. It knows all the ingress resources in your cluster and does its routing based on those. – The Fool May 17 '22 at 14:27