大网数据广告活动
服务器运维问答

how to isolate kubernetes namespaces but allow access from outside

· 52CE 我爱测

I have a Kubernetes cluster setup using kubeadm I'm trying to define a network policy which restricts access from outside the namespace but doesn't block access from outside (external IP) to elaborate I want the pods to be access…

问题原文

原帖链接 · moses · CC BY-SA 4.0

I have a Kubernetes cluster setup using kubeadm
I'm trying to define a network policy which restricts access from outside the namespace but doesn't block access from outside (external IP)
to elaborate I want the pods to be accessible from other pods in the namespace and via external IP address but not from other namespaces
any ideas?

已采纳解答

原帖链接 · moses · CC BY-SA 4.0

I used the following network policy and it worked for me

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  namespace: policy-test
  name: deny-from-other-namespaces
spec:
  podSelector:
    matchLabels:
  ingress:
  - from:
    - podSelector: {}
    - namespaceSelector:
        matchLabels:
          access: "true"  

based on what I know the external access is granted through kube-proxy which is a pod in kube-system namespace. this network policy will allow all the pods from policy-test namespace and any namespace with access=true label
applying this network policy and adding the access=true label to kube-system namespace will solve the issue

adding the label :

kubectl label namespace/kube-system access=true

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-09-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。