In order to keep a POD running it should to be performing certain task, otherwise Kubernetes will find it unnecessary, therefore it stops. There are many ways to keep a POD running.
I have faced similar problems when I needed a POD just to run continuously without doing any useful operation. The following are the two ways those worked for me:
Although the first option is easier than the second one and may suffice the requirement, it is not the best option. As, there is a limit as far as the number of seconds you are going to assign in the sleep command. But a container with infinite loop running inside it never exits.
However, I will describe both the ways(Considering you are running busybox container):
1. Sleep Command
apiVersion: v1
kind: Pod
metadata:
name: busybox
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox
ports:
- containerPort: 80
command: ["/bin/sh", "-ec", "sleep 1000"]
nodeSelector:
beta.kubernetes.io/os: linux
2. Infinite Loop
apiVersion: v1
kind: Pod
metadata:
name: busybox
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox
ports:
- containerPort: 80
command: ["/bin/sh", "-ec", "while :; do echo '.'; sleep 5 ; done"]
nodeSelector:
beta.kubernetes.io/os: linux
Run the following command to run the pod:
kubectl apply -f <pod-yaml-file-name>.yaml
Hope it helps!