In my configuration, very basic one (Only calico network, no apps yet) I have nginx-ingress running as NodePort - binding on port 30080. This port should be accessible only from localhost, but k8s opened this port for everyone, and since it's binding on 0.0.0.0 it's wide open now.
So I want to force kube-proxy to bind this port to 127.0.0.1 only.
I've tried modifing configmap to nginx-ingress (bind-address) but no luck with that.
Since this port is attached to kube-proxy - i was looking for kube-proxy config, but no luck at all. I've found yaml config file in /var/lib/kube-proxy but modifing it didn't change this.
After restarting pods, they are still binded to 0.0.0.0
I've tried many ways from internet, but still no luck.
Cluster was initialised with: kubeadm init --pod-network-cidr=10.XXX.XXX.XXX/XX --apiserver-advertise-address=X.X.X.X
Not sure if this is what you have been looking for however this way, it will listen on
127.0.0.1:NodePort
You need to change
kube-proxy
configmap but notbindAddress:
(it should be left as it wasbindAddress: 0.0.0.0
) and default valuenodePortAddresses: null
should be changed tonodePortAddresses: ["127.0.0.0/8"]
. It must be["127.0.0.0/8"]
as if you will change just to127.0.0.1/8
kube-proxy
pod will crush.Change
nodePortAddresses: null
tonodePortAddresses: ["127.0.0.0/8"]
and save using:wq
. As defaultedit
will open inVI
text editor.If you would like use nano as text editor you must use
KUBE_EDITOR="nano" kubectl edit cm kube-proxy -n kube-system
.As example i have used
Nginx deployment
from this docs. Only chage was addtype: NodePort
to service YAML.Now you will need to apply this new configuration to kube-proxy. Easiest way is to delete
kube-proxy
pod asdaemonset.apps/kube-proxy
will create new one with new config.Original output:
Output with changed
nodePortAddresses: