简体   繁体   中英

Kubernetes: Remove NetworkPolicies

I have been experimenting with network policies, and now pods can no longer communicate with each other though I have deleted all the policies.

Namespace

apiVersion: v1
kind: Namespace
metadata:
    name: staging
    labels:
        env: staging

Service A

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-a
  namespace: staging
spec:
  replicas: 1
  selector:
    matchLabels:
      app: service-a
  template:
    metadata:
      labels:
        app: service-a
    spec:
      containers:
      - name: service-a
        image: busybox:1.33.1
        command: ["nc", "-lkv", "-p", "8080", "-e", "/bin/sh"]
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: service-a
  namespace: staging
spec:
  type: ClusterIP
  selector:
    app: service-a
  ports:
  - port: 8080

Service B

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-b
  namespace: staging
spec:
  replicas: 1
  selector:
    matchLabels:
      app: service-b
  template:
    metadata:
      labels:
        app: service-b
    spec:
      containers:
      - name: service-b
        image: busybox:1.33.1
        command: ["nc", "-lkv", "-p", "8080", "-e", "/bin/sh"]
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: service-b
  namespace: staging
spec:
  type: ClusterIP
  selector:
    app: service-b
  ports:
  - port: 8080

Testing Communication

kubectl -n staging exec service-a-7c66d7cdf8-72gqq --  nc -vz service-b

Expected behaviour is that they can contact each other, but instead there is a timeout. So I tjeck if there are any network policies left.

kubectl -n staging get networkpolicy
>No resources found in staging namespace.

What I have tried

I have deleted the namespace, recreated it and recreated the two services. I have gone through all namespaces looking for network policies to delete them, but there are none!

Before I started experimenting with the networkspolicies everything worked fine, but now I cannot get things working again. For the network controller I am using cillum.

I am pretty dumb, I simply forgot to write the port the second time around. It should be:

kubectl -n staging exec service-a-7c66d7cdf8-72gqq --  nc -vz service-b 8080

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM