kind: Namespace
apiVersion: v1
metadata:
name: testingnp
annotations:
net.beta.kubernetes.io/network-policy: |
{
"ingress": {
"isolation": "DefaultDeny"
}
}
kubectl run nginx --image=nginx --replicas=2 --namespace=testingnp
kubectl expose deployment nginx --port=80 --namespace=testingnp
echo '
kind: NetworkPolicy
apiVersion: extensions/v1beta1
metadata:
name: access-nginx
namespace: testingnp
spec:
podSelector:
matchLabels:
run: nginx
ingress:
- from:
- podSelector:
matchLabels:
access: "true"
' | kubectl create -f -
kubectl get networkpolicies --namespace=testingnp