Network Policy Is Not Working in Kubernetes

72 Views Asked by At

app.yml file

   apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
        app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: default
  labels:
    app: nginx
 
spec:
  externalTrafficPolicy: Local
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer

network_policy.yml file

    apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-ingress-egress-app1
spec:
  podSelector:
    matchLabels:
      app: nginx
  policyTypes:
  - Ingress
  - Egress
  ingress:
  - ports:
    - port: 8080
      protocol: TCP
  egress:
  - ports:
    - port: 3289
      protocol: TCP

After applying the network policy, I can access the application through the load balancer URL though I have not opened port 80 Ingress in the network_policy.yml file. Please find both app.yml and network_policy.yml files. Please help me so that I can fix this issue. I am using AWS EKS Cluster which is using Amazon VPC CNI.

0

There are 0 best solutions below