Can anyone help with the below two questions?
Make sure traffic coming from Pods of Namespace “A” from port 80 can access all pods in Namespace “B”.
Edit pod with port 80 and name HTTP. Create service for HTTP.
Which lab you have your questions in ?
The following manifest restricts traffic to only pods in namespaces that has label
purpose=production. Save it to
web-allow-prod.yaml and apply to the cluster:
kind: NetworkPolicy apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1> metadata: name: web-allow-prod spec: podSelector: matchLabels: app: web ingress: - from: - namespaceSelector: matchLabels: purpose: production
@Bansi the second question that you asked. At
ports: - name: http containerPort: 80
To create service, http here refers to the name of the port. So, you can just give
--port=80 in the imperative command. Assuming, you want to expose your service externally - I am using service of type - NodePort
k expose deploy deployment-name --name service-name --port=80 --type=NodePort
@Pradeep I was unsure if we can provide a name when creating service. So I guess we cannot provide name for service but just the port
@Mohamed Ayman Thank you I did come across this example. I was wondering if there is a way we can specify the namespace even under the below section as the question was all pods from one namespace to another namespace.
spec: podSelector: matchLabels: app: web
Check all the examples and scenarios here: