Change:
While working through the Killer Shell scenario for NetworkPolicies to prep for my CKA, I used the example but it failed validation. When I looked at their solution it had one tiny difference, they had a - in front of "ports:" and you guys didn't. Based on the reference docs it appears ports does expect an array which would mean that you are missing the hyphen. docs: solution from
This issue is currently awaiting triage. SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the label. The label can be by org members by writing in a comment. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
The indentation of list items may be the source of confusion. Once you indent all list items under a given key, the parent element of the 'ports' attribute becomes more evident. The example on the website is correct. I'm not sure about the solution from If you put as the first key of a list item object, if will carry the bar for that list item, if is not the the first key, you will indent it rather than adding another before it. Anyway, I'm fixing the example in hope things become clearer for readers.

Discussion:
An example NetworkPolicy might look like this: <del> ```yaml apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: test-network-policy namespace: default spec: podSelector: matchLabels: role: db policyTypes: - Ingress - Egress ingress: - from: - ipBlock: cidr: 172.17.0.0/16 except: - 172.17.1.0/24 - namespaceSelector: matchLabels: project: myproject - podSelector: matchLabels: role: frontend ports: - protocol: TCP port: 6379 egress: - to: - ipBlock: cidr: 10.0.0.0/24 ports: - protocol: TCP port: 5978 ``` </del> <ins> {{< codenew file="service/networking/networkpolicy.yaml" >}} </ins> {{< note >}} POSTing this to the API server for your cluster will have no effect unless your chosen networking solution supports network policy.

"service/networking": { "curlpod":                                 {&apps.Deployment{}}, "custom-dns":                              {&api.Pod{}}, <ins> "default-ingressclass":                    {&networking.IngressClass{}}, </ins> "dual-stack-default-svc":                  {&api.Service{}}, "dual-stack-ipfamilies-ipv6":              {&api.Service{}}, "dual-stack-ipv6-svc":                     {&api.Service{}},

"name-virtual-host-ingress":               {&networking.Ingress{}}, "name-virtual-host-ingress-no-third-host": {&networking.Ingress{}}, "namespaced-params":                       {&networking.IngressClass{}}, <ins> "networkpolicy":                           {&networking.NetworkPolicy{}}, </ins> "network-policy-allow-all-egress":         {&networking.NetworkPolicy{}}, "network-policy-allow-all-ingress":        {&networking.NetworkPolicy{}}, "network-policy-default-deny-egress":      {&networking.NetworkPolicy{}},

<ins> apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: test-network-policy namespace: default spec: podSelector: matchLabels: role: db policyTypes: - Ingress - Egress ingress: - from: - ipBlock: cidr: 172.17.0.0/16 except: - 172.17.1.0/24 - namespaceSelector: matchLabels: project: myproject - podSelector: matchLabels: role: frontend ports: - protocol: TCP port: 6379 egress: - to: - ipBlock: cidr: 10.0.0.0/24 ports: - protocol: TCP port: 5978 </ins>