Limit the namespace from web url resource

1/31/2020

According to the ingress nginx controller doc, it remind the object will use the ingress-nginx namespace, and can change to other namespace with --watch-namespace tag.

But when I using

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx0.28.0/deploy/static/provider/aws/service-l7.yaml --watch-namespace=default

It report

Error: unknown flag: --watch-namespace
See 'kubectl apply --help' for usage.
-- ccd
kubernetes

2 Answers

1/31/2020

You are messing up with one flag with others. By default following command will deploy the controller in ingress-nginx namespace. But you want it to be in some other namespace like default. To do so, you need to pass kubectl's flag like -n or --namespace.

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx0.28.0/deploy/static/provider/aws/service-l7.yaml --namespace default

NB:

--watch-namespace is a flag of nginx-ingress-controller. It is used while running the binary inside the container. It needs to be set from deployment.spec.contianers[].args[]. It is used to bind the controller's watch in a single k8s namespace(by default it watches objects of all namespaces).

-- Kamol Hasan
Source: StackOverflow

1/31/2020

You need to set --watch-namespace in the args section of nginx ingress controller deployment yaml

args:
  - /nginx-ingress-controller
  - --configmap=$(POD_NAMESPACE)/$(NGINX_CONFIGMAP_NAME)
  - --tcp-services-configmap=$(POD_NAMESPACE)/$(TCP_CONFIGMAP_NAME)
  - --udp-services-configmap=$(POD_NAMESPACE)/$(UDP_CONFIGMAP_NAME)
  - --publish-service=$(POD_NAMESPACE)/$(SERVICE_NAME)
  - --annotations-prefix=nginx.ingress.kubernetes.io
  - --watch-namespace=namespace

https://github.com/kubernetes/ingress-nginx/blob/master/deploy/cloud-generic/deployment.yaml

-- Arghya Sadhu
Source: StackOverflow