題目:叢集內建立有pod: ithome-test,及其service: ithome-service,建立一個NetworkPolicy(ingress-to-ithome),讓外部連線能轉導到ithome-service (port: 80),不可異動已部署的物件
kubectl apply -f ingress-to-ithome.yaml
kubectl get pod ithome-test --show-labels
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: ingress-to-ithome
namespace: default
spec:
podSelector: # 依照label標定
matchLabels:
run: ithome-test
policyTypes:
- Ingress # 外部流量設定
ingress:
- ports:
- protocol: TCP
port: 80
為確認是否外部流量能否依指定的policy打到pod: ithome-test,安裝輕量版的curl
kubectl run curl-tool --image=alpine/curl --rm -it -- sh