Complete the code to define a NodePort service in Kubernetes.
apiVersion: v1 kind: Service metadata: name: my-service spec: type: [1] selector: app: MyApp ports: - protocol: TCP port: 80 targetPort: 9376
The type field set to NodePort exposes the service on each Node's IP at a static port.
Complete the code to specify the port number for the NodePort service.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
nodePort: [1]The nodePort must be a port number between 30000 and 32767 for NodePort services.
Fix the error in the service definition by completing the missing field.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
[1]: 9376
nodePort: 30001portNumber instead of targetPort causes the service to fail.containerPort with targetPort in the service spec.The correct field to specify the port on the pod is targetPort.
Fill both blanks to complete the NodePort service ports configuration.
ports: - protocol: [1] port: [2] targetPort: 8080 nodePort: 30010
The protocol is usually TCP and the service port is commonly 80 for HTTP.
Fill all three blanks to complete the NodePort service YAML snippet.
apiVersion: v1 kind: Service metadata: name: example-service spec: type: [1] selector: app: example ports: - protocol: [2] port: [3] targetPort: 5000 nodePort: 31000
The service type must be NodePort, protocol TCP, and port 80 to expose the app on port 80 via NodePort.
