I having my Pod manifest as below:
apiVersion: v1
kind: Pod
metadata:
name: pod-nginx-container
spec:
containers:
- name: nginx-alpine-container-1
image: nginx:alpine
ports:
- containerPort: 80
And I can get a shell to the Container running my Nginx using kubectl exec --stdin --tty pod-nginx-container -- /bin/sh
My question is does Kubernetes always give a shell to the running container? I mean suppose I have created my own image of Tomcat webserver, and when I use that image then will I still get the shell to login to the container running Tomcat?
Kubernetes schedules Pods to nodes. A Pod consists of one or more containers - that are instantiated from container images.
A container image contains a command that will run as the main process but it can also contain other binaries and also a full Linux "userland" like e.g. Ubuntu with shell and lots of tools.
Container images can be built from "scratch" without any other software than e.g. your app, but typically contain some more software for your app to be runnable e.g. glibc. See distroless for minimal base images that does not contain a shell.
My question is does Kubernetes always give a shell to the running container? I mean suppose I have created my own image of Tomcat webserver, and when I use that image then will I still get the shell to login to the container running Tomcat?
Your container contain a shell, only if you have built in a shell - most likely by using a base image that contain a shell e.g. alpine or ubuntu.
It depends on what do you do in your Dockerfile before building a container image with docker build