update k8s ingress via service account

9/7/2020

I have an app where I regularly need to add new domains. Right now I need to add or delete an ingress every time I add or remove a domain.

I would like to automate this.

I have a ui where a user has a list of registered domains and can add a domain to the app. So when the user sets this up I want to automatically update the ingress.

The way I would go about this is via a service account that manages these ingresses. Are there any best practices for this or are there ingress controllers that already have an api for this?

-- errnesto
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

9/7/2020

Ingress controllers don't have any API exposed for this and don't need to. You will need to call kubernetes REST API to update the ingress resource. You can use kubernetes client libraries available in multiple languages to perform this using a service account or kubeconfig file.

You will need to define RBAC using Role and Rolebinding to authorize the service account or the user used to call the REST API.

Use PUT or PATCH to change host in below API

/apis/networking.k8s.io/v1/namespaces/{namespace}/ingresses

When an ingress resource is updated this way ingress controller will be notified with the change because ingress controller watches on ingress resource for any change.

-- Arghya Sadhu
Source: StackOverflow