Ingress Allow Access Only From Certain IP Addresses
Whitelist annotations depend on which concrete ingress is used by for nginx one it will be:
nginx.ingress.kubernetes.io/whitelist-source-range
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- name: nginx
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: ClusterIP
selector:
app: nginx
ports:
- name: nginx
protocol: TCP
port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
annotations:
# https://medium.com/@maninder.bindra/using-nginx-ingress-controller-to-restrict-access-by-ip-ip-whitelisting-for-a-service-deployed-to-bd5c86dc66d6
# nginx.ingress.kubernetes.io/whitelist-source-range: 168.140.34.181/32
# https://blog.container-solutions.com/kubernetes-quick-tip
# ingress.kubernetes.io/whitelist-source-range: 168.140.34.181/32
# https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#whitelist-source-range
nginx.ingress.kubernetes.io/whitelist-source-range: 168.140.34.181/32
spec:
rules:
- host: nginx.mac-blog.org.ua
http:
paths:
- backend:
service:
name: nginx
port:
number: 80
path: /
pathType: ImplementationSpecific
More annotations can be found here