Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to exec into an initContainer in Kubernetes

I have a init container in which I'm storing file but while running it's showing the file is not present. Is there any way I can exec inside init container and check where the file is being stored.

like image 237
Cycl0n3 Avatar asked Mar 20 '19 10:03

Cycl0n3


People also ask

Can we exec into init container?

One of the things that I do with init containers (assuming you have the source) is to put a sleep 600 on failure in the entrypoint. At least for debugging. This lets you exec into the container to poke around to see the cause of the failure. Show activity on this post.

How do I access the init container?

Accessing logs from Init Containers Init Containers that run a shell script print commands as they're executed. For example, you can do this in Bash by running set -x at the beginning of the script.

What is initcontainer in Kubernetes?

In this Kubernetes tutorial we learned about initContainer and it's usage in Kubernetes Cluster nodes. A Pod can have multiple containers running apps within it, but it can also have one or more init containers, which are run before the app containers are started.

How does the kubelet run the init containers?

During Pod startup, the kubelet delays running init containers until the networking and storage are ready. Then the kubelet runs the Pod's init containers in the order they appear in the Pod's spec. Each init container must exit successfully before the next container starts.

What is readinessprobe in Kubernetes init containers?

Init containers have all of the fields of an app container. However, Kubernetes prohibits readinessProbe from being used because init containers cannot define readiness distinct from completion. This is enforced during validation.

How to initialize a Kubernetes pod?

The regular container will only be started once the init container has been started An init container in a Pod must run and complete before any other application containers in the Pod start. This is a great way to initialize a Kubernetes Pod.


1 Answers

Use kubectl describe <pod> to get the id of the initContainer you need to exec into then use kubectl exec -ti <pod> -c <container> sh to access its shell. You may need to add some kind of delay, like sleep to the initContainer to access it before it completes or fails.

like image 59
kellanburket Avatar answered Sep 24 '22 22:09

kellanburket