1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/samples/RestrictNodePort.md

34 lines
782 B
Markdown
Raw Normal View History

2019-11-11 22:09:07 +00:00
# Restrict use of `NodePort` services
2019-10-23 21:06:03 +00:00
A Kubernetes service of type `NodePort` uses a host port (on every node in the cluster) to receive traffic from any source.
Kubernetes Network Policies cannot be used to control traffic to host ports.
Although NodePort services can be useful, their use should be limited to services with additional upstream security checks.
## Policy YAML
2019-11-12 02:21:16 +00:00
[restrict_node_port.yaml](more/restrict_node_port.yaml)
2019-10-23 21:06:03 +00:00
````yaml
apiVersion: kyverno.io/v1alpha1
kind: ClusterPolicy
metadata:
2019-11-11 22:09:07 +00:00
name: restrict-node-port
2019-10-23 21:06:03 +00:00
spec:
rules:
2019-11-11 05:34:22 +00:00
- name: validate-node-port
2019-10-23 21:06:03 +00:00
match:
resources:
kinds:
- Service
validate:
2019-11-11 22:09:07 +00:00
message: "Service of type NodePort is not allowed"
2019-10-23 21:06:03 +00:00
pattern:
spec:
type: "!NodePort"
````