Openshift - Run a basic container with alpine, java and jmeter
On your local machine, you are likely using docker run -it <my_container_image>
or similar. Using the -it
option will run an interactive shell in your container without you specifying a CMD
and will keep that shell running as the primary process started in your container. So by using this command, you are basically already specifying a command.
Kubernetes expects that the container image contains a process that is run on start (CMD
) and that will run as long as the container is alive (for example a webserver).
In your case, Kubernetes is starting the container, but you are not specifying what should happen when the container image is started. This leads to the container immediately terminating, which is what you can see in the Events above. Because you are using a Deployment
, the failing Pod is then restarted again and again.
A possible workaround to this is to run the sleep
command in your container on startup by specifing a command
in your Pod like so:
apiVersion: v1kind: Podmetadata: name: command-demo labels: purpose: demonstrate-commandspec: containers: - name: command-demo-container image: alpine command: ["/bin/sleep", "infinite"] restartPolicy: OnFailure
This will start the Pod and immediately run the /bin/sleep infinite
command, leading to the primary process being this sleep
process that will never terminate. Your container will now run indefinitely. Now you can use oc rsh <name_of_the_pod
to connect to the container and run anything you would like interactively (for example jmeter
).