Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with k8s.io/docs/concepts/services-networking/network-policies/ #40858

Closed
EricBuist opened this issue Apr 26, 2023 · 7 comments · Fixed by #41140
Closed

Issue with k8s.io/docs/concepts/services-networking/network-policies/ #40858

EricBuist opened this issue Apr 26, 2023 · 7 comments · Fixed by #41140
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. language/en Issues or PRs related to English language sig/network Categorizes an issue or PR as relevant to SIG Network. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@EricBuist
Copy link

The page is not covering a pretty common case of targeting multiple namespaces by name. I need an egress policy allowing to send to pods in two namespaces, cannot find any way of doing it, will have to search on Google and hit tons of StackOverflow posts suggesting random solutions that may or may not work. I don't have enough privileges on the Kubernetes cluster to add labels to namespaces in order to search by label. This could be a lack of flexibility of network policies, or something missing from the documentation.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 26, 2023
@mengjiao-liu
Copy link
Member

mengjiao-liu commented Apr 27, 2023

/language en

@k8s-ci-robot k8s-ci-robot added the language/en Issues or PRs related to English language label Apr 27, 2023
@k8s-ci-robot
Copy link
Contributor

@mengjiao-liu: The label(s) kind/, kind/network cannot be applied, because the repository doesn't have them.

In response to this:

/kind network
/language en

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mengjiao-liu
Copy link
Member

/sig network

@k8s-ci-robot k8s-ci-robot added the sig/network Categorizes an issue or PR as relevant to SIG Network. label Apr 27, 2023
@tengqm
Copy link
Contributor

tengqm commented Apr 28, 2023

/triage accepted
/kind feature

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. kind/feature Categorizes issue or PR as related to a new feature. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 28, 2023
@mrgiles
Copy link
Contributor

mrgiles commented May 13, 2023

/assign

@mrgiles
Copy link
Contributor

mrgiles commented May 13, 2023

Hello, @EricBuist. unfortunately, it is not possible to directly specify the names of the namespaces in a NetworkPolicy. You must use a namespaceSelector with matchLabels or matchExpressions to select the namespaces based on their labels.

Here is an example using labels:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: my-network-policy
spec:
  podSelector:
    matchLabels:
      app: my-app
  policyTypes:
  - Egress
  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          namespace: namespace-1
    - namespaceSelector:
        matchLabels:
          namespace: namespace-2

You will have to find somebody in your organization with enough privileges to add the labels for you, if you don't have access to do it yourself.

Thanks!

FYI: @tengqm

@tengqm
Copy link
Contributor

tengqm commented May 14, 2023

It would be desirable to incorporate comments by @mrgiles in the docs, considering that others may have the same questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. language/en Issues or PRs related to English language sig/network Categorizes an issue or PR as relevant to SIG Network. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants