keep container running on Kubernetes

0 votes
I've tried running container by using kubectl run-container command like

kubectl run-container test_container ubuntu:latest --replicas=1

but container exits in few seconds and ReplicationController launches it again repeatedly. Is there a way to keep the containers running?
Aug 30, 2018 in Kubernetes by Hannah
• 18,520 points
13,848 views

2 answers to this question.

0 votes

Provide your container with a task that will never finish. Something like this should work:

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
spec:
  containers:
  - name: ubuntu
    image: ubuntu:latest
    # Just spin & wait forever
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]

If you are interested in knowing more about Kubernetes, then consider taking  CKA Certification Course.

answered Aug 30, 2018 by Kalgi
• 52,350 points
0 votes

Try using this CMD in your Dockerfile:

CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"

This command keeps the container up ans running or alive until its told to stop

answered Aug 30, 2018 by Nilesh
• 7,060 points

Related Questions In Kubernetes

0 votes
1 answer

oci runtime error while running kubernetes on rancher cluster

You need to switch Docker to 1.12.x; ...READ MORE

answered Sep 6, 2018 in Kubernetes by Kalgi
• 52,350 points
1,208 views
0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Running Kubernetes on Mac

This error occurs becaouse you have to ...READ MORE

answered Aug 28, 2018 in Kubernetes by Kalgi
• 52,350 points
698 views
0 votes
2 answers

NoSuchBucket error when running Kubernetes on AWS

It was a bug on their part. ...READ MORE

answered Sep 4, 2018 in Kubernetes by Nilesh
• 7,060 points
951 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP