Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal: looking for the app
You exec'd into your Pod. Your app wasn't there. A Pod is a group of containers running together, and you ran kubectl exec to open a shell inside one. But when you list slash app, the shell says no such file or directory. Why is the folder missing?
$ kubectl exec -it web-pod -- sh
Defaulted container "log-shipper" out of: log-shipper, app
/ # ls /app
ls: /app: No such file or directoryDefaulted container "log-shipper" out of: log-shipper, app
Here's why. web-pod holds two containers, log-shipper and app. When you run kubectl exec without -c, kubectl doesn't ask which one you mean. It picks the Pod's default container, usually the first listed, which is log-shipper. That's what the highlighted defaulted note is telling you. The app container never gets chosen.
Fix: name the container with -c
The fix is the -c flag. Here we add -c app, so kubectl opens the shell in the container named app instead of the default. Now ls /app shows package.json and server.js. These file names are just illustrative. The same flag works with any container name in the Pod.
$ kubectl exec -it web-pod -c app -- sh
/ # ls /app
package.json server.jsTwo containers, one Pod. Pick the one you meant.
Two containers, one Pod. Pick the one you meant. Read the defaulted note kubectl prints, and add -c with the container's name.
