Created
December 12, 2022 21:37
-
-
Save abossard/6df395b6f96e79a2220714d2d24644ed to your computer and use it in GitHub Desktop.
Example for network policies with ingress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: myapp | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: | |
app: myapp | |
template: | |
metadata: | |
labels: | |
app: myapp | |
spec: | |
containers: | |
- name: myapp | |
image: nginx | |
resources: | |
limits: | |
memory: "128Mi" | |
cpu: "500m" | |
ports: | |
- containerPort: 80 | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: myapp | |
spec: | |
type: LoadBalancer | |
selector: | |
app: myapp | |
ports: | |
- port: 80 | |
targetPort: 80 | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: myingress | |
annotations: | |
nginx.ingress.kubernetes.io/rewrite-target: /$2 | |
labels: | |
name: myingress | |
spec: | |
ingressClassName: nginx | |
rules: | |
- http: | |
paths: | |
- pathType: Prefix | |
path: /myapp(/|$)(.*) | |
backend: | |
service: | |
name: myapp | |
port: | |
number: 80 | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: NetworkPolicy | |
metadata: | |
name: allow-ingress-controller-to-myapp | |
spec: | |
ingress: | |
- from: | |
- podSelector: | |
matchLabels: | |
app.kubernetes.io/name: ingress-nginx | |
- namespaceSelector: | |
matchLabels: | |
name: ingress-nginx | |
ports: | |
- port: 80 | |
protocol: TCP | |
- from: | |
- podSelector: | |
matchLabels: | |
app: myapp | |
ports: | |
- port: 80 | |
protocol: TCP | |
podSelector: | |
matchLabels: | |
app: myapp | |
policyTypes: | |
- Ingress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment