Certified Kubernetes Administrator (CKA) Practice Test

1 / 400

How do you expose a specific container port within a deployment in Kubernetes?

Add a containerPort section in the Deployment specification

To expose a specific container port within a deployment in Kubernetes, adding a containerPort section in the Deployment specification is essential for defining how the port is utilized. This section indicates which port the container listens on, making it possible for other resources within the cluster, such as services, to reference that specific port when directing traffic to the container.

This method is particularly effective because it integrates closely with the deployment structure in Kubernetes. It ensures that the container is aware of its networking configuration and allows Kubernetes to manage network traffic appropriately. This configuration not only facilitates internal communication but also provides a basis for further service exposure through a Service resource, which can expose the deployment to external traffic based on the defined container port.

Utilizing the kubectl port-forward command is more of a temporary method for accessing a specific pod without changing its networking configuration, while creating a standalone Pod bypasses the benefits of a Deployment, such as scaling and updating. Meanwhile, using kubelet to expose the container does not align with standard Kubernetes practices for service exposure, as kubelet is responsible for managing pods and their lifecycle rather than directly handling access strategies.

Therefore, specifying the container port within the Deployment specification is a critical step for setting up network access in a way that adheres to Kubernetes best

Get further explanation with Examzify DeepDiveBeta

Use kubectl port-forward command

Create a Pod for the container

Use kubelet to expose the container

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy