cancel
Showing results for 
Search instead for 
Did you mean: 
Ravi_Shanker
Flight Engineer
Flight Engineer
  • 176 Views

Chapter 3 Guided exercise S3 Object

The guided exercises gives a oc command to exec in a deployment. Is this something really possible ? I don't have my labs running now, but fundamentally I see it as a wrong statement. Even if the command works for some reason does it qualify to be used as best practice ?Screenshot from 2025-09-27 13-18-58.jpeg

 

 

Certification ID: 111-010-393
3 Replies
  • 142 Views

Sure, it's definitely possible and common for ad-hoc troubleshooting. One of the examples in the official Kubernetes documentation illustrates how to run a command in a deployment with `kubectl exec`: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_exec/

As stated in the documentation, when targeting a controller such as a deployment instead of an individual pod for `kubectl exec`, Kubernetes selects the first pod managed by the controller. So what it actually does is run the command within the first (or selected) container of the first pod managed by the controller, i.e. essentially the same as listing the pods of the deployment and running `kubectl exec` with the name of the first pod.

Is it best practice? It depends. Running a container shell within a pod or workload is often a quick and dirty way to identify the root cause of an application or component failure. Sometimes it might be required to resolve issues immediately within stateful workloads or components before the situation deteriorates and the fastest way is to spin up a container shell and run ad-hoc commands to fix or workaround the issue.

On the other hand, running ad-hoc commands in a container shell is not reproducible, automatable and difficult to audit. So in that sense it's far from best practice. Also some organizational contexts may advise against or outright forbid exec'ing into a container shell for security or compliance reasons, either through administrative or technical means.

  • 89 Views

Running oc exec directly in a deployment isn’t possible since deployments aren’t pods. The recommended approach is to exec into a running pod created by the deployment. So, using oc exec on a deployment isn’t best practice or technically correct.

Chetan_Tiwary_
Community Manager
Community Manager
  • 23 Views

@Ravi_Shanker Yes it is possible. It will select  from the first pod of the deployment, using the first container by default. 

However, yes it is not best practice and sometimes it is ambiguous for example in the case of replicas or diff versions  or permissions. 

I will report it to the course development team for further brainstroming. Thanks for reporting this to us. 

0 Kudos
Join the discussion
You must log in to join this conversation.