Linux Foundation CKS Exam - Topic 6 Question 66 Discussion
You can switch the cluster/configuration context using the following command:
[desk@cli] $kubectl config use-context dev
A default-deny NetworkPolicy avoid to accidentally expose a Pod in a namespace that doesn't have any other NetworkPolicy defined.Task: Create a new default-deny NetworkPolicy nameddeny-networkin the namespacetestfor all traffic of type Ingress + EgressThe new NetworkPolicy must deny all Ingress + Egress traffic in the namespacetest.Apply the newly createddefault-denyNetworkPolicy to all Pods running in namespacetest.You can find a skeleton manifests file at /home/cert_masters/network-policy.yaml
A) Explanation:
master1 $k get pods -n test --show-labels
NAME READY STATUS RESTARTS AGE LABELS
test-pod 1/1 Running 0 34s role=test,run=test-pod
testing 1/1 Running 0 17d run=testing
$vim netpol.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-network
namespace: test
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
master1 $k apply -f netpol.yaml
Explanation
controlplane $ k get pods -n test --show-labels
NAME READY STATUS RESTARTS AGE LABELS
test-pod 1/1 Running 0 34s role=test,run=test-pod
testing 1/1 Running 0 17d run=testing
master1 $ vim netpol1.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-network
namespace: test
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
master1 $ k apply -f netpol1.yaml
Reference:
https://kubernetes.io/docs/concepts/services-networking/network-policies/
Explanation
controlplane $ k get pods -n test --show-labels
NAME READY STATUS RESTARTS AGE LABELS
test-pod 1/1 Running 0 34s role=test,run=test-pod
testing 1/1 Running 0 17d run=testing
master1 $ vim netpol1.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-network
namespace: test
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
master1 $ k apply -f netpol1.yaml
Reference:
https://kubernetes.io/docs/concepts/services-networking/network-policies/
Gregg
10 months agoBernardo
10 months agoDarell
10 months agoGennie
10 months agoMel
11 months agoKayleigh
11 months agoAlpha
11 months agoGerardo
11 months agoCarylon
11 months agoBrett
11 months agoLorita
11 months agoLeonida
11 months agoRebeca
11 months agoKayleigh
12 months agoSvetlana
12 months agoAlbert
2 years agoLajuana
2 years agoBrandee
2 years agoMatthew
2 years agoKenneth
2 years agoGerman
2 years agoJeannetta
2 years agoHui
2 years agoValentin
2 years agoOretha
2 years agoMatthew
2 years agoCarlota
2 years agoAnnmarie
2 years agoTheodora
2 years ago