The following can be used to perform network troubleshooting.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: server-egress-np
namespace: <namespace>
spec:
podSelector:
matchLabels:
app: my-net-app
policyTypes:
- Egress
egress:
- to:
- ipBlock:
cidr: <ip attempting to connect to>/32
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: my-net-app
name: my-net-pod
spec:
containers:
- image: registry.net/kubepublic/00000-rhel7-nettools:v2.2
name: net-test
command: ["/bin/bash", "-c", "sleep 3600" ]
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
Once the pod has been created, the following command can be run to perform actions, such as a ping.
kubectl exec my-net-pod -- /bin/bash -c "/usr/bin/ping <ip in cidr block in network policy>"