Complete the code to create a Kubernetes Service that exposes pods on port 80.
kubectl expose pod mypod --port=[1] --target-port=8080
The --port flag defines the port the Service will expose. Port 80 is the standard HTTP port.
Complete the code to select pods with label app=web for the Service.
kubectl expose pod mypod --port=80 --selector=[1]
The selector uses key=value format to match pods with label app=web.
Fix the error in the Service YAML to ensure stable networking by specifying the correct type.
apiVersion: v1
kind: Service
metadata:
name: myservice
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: [1]ClusterIP is the default Service type that provides stable internal networking within the cluster.
Fill both blanks to complete the Service YAML that ensures stable networking and selects pods correctly.
apiVersion: v1 kind: Service metadata: name: stable-service spec: type: [1] selector: app: [2] ports: - port: 80 targetPort: 8080
Using ClusterIP ensures stable internal networking. The selector app: myapp matches the pods to route traffic.
Fill all three blanks to create a Service YAML that provides stable networking, selects pods, and exposes port 80.
apiVersion: v1 kind: Service metadata: name: [1] spec: type: [2] selector: app: [3] ports: - port: 80 targetPort: 8080
The service name is stable-service, type ClusterIP ensures stable networking, and selector app: myapp matches the pods.