Complete the code to create a Kubernetes Service that exposes a Pod on port 80.
kubectl expose pod my-pod --port=[1]The standard HTTP port is 80, so exposing the pod on port 80 allows web traffic.
Complete the command to list all Services in the default namespace.
kubectl get [1]Services are listed with 'kubectl get services'.
Fix the error in the Service YAML to correctly specify the target port.
spec: ports: - port: 80 targetPort: [1]
The targetPort should be the port number the container listens on, usually 80 for HTTP.
Fill both blanks to create a NetworkPolicy that allows traffic only from pods with label 'app=frontend' to pods with label 'app=backend'.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-frontend
spec:
podSelector:
matchLabels:
app: [1]
ingress:
- from:
- podSelector:
matchLabels:
app: [2]The policy selects pods with label 'app=backend' and allows ingress from pods labeled 'app=frontend'.
Fill all three blanks to define a Service of type NodePort exposing port 80 and targeting port 8080 on pods labeled 'app=web'.
apiVersion: v1 kind: Service metadata: name: web-service spec: type: [1] selector: app: [2] ports: - port: [3] targetPort: 8080
The Service type should be 'NodePort' or 'LoadBalancer' to expose externally; here 'NodePort' is chosen. The selector matches pods labeled 'app=web'. The port exposed is 80, targeting 8080 on pods.