https://github.com/robert076/initcontainers
Small example for initContainers I read. Also contains instructions on displaying logs in a better way (either a specific container or the last 2 hours for example etc.)
https://github.com/robert076/initcontainers
initcontainer k8s kubernetes
Last synced: 8 months ago
JSON representation
Small example for initContainers I read. Also contains instructions on displaying logs in a better way (either a specific container or the last 2 hours for example etc.)
- Host: GitHub
- URL: https://github.com/robert076/initcontainers
- Owner: Robert076
- License: apache-2.0
- Created: 2025-05-24T08:05:13.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-25T06:10:24.000Z (about 1 year ago)
- Last Synced: 2025-07-03T18:52:24.718Z (11 months ago)
- Topics: initcontainer, k8s, kubernetes
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📦 initContainers
initContainers is a feature provided by K8s pods to run setup scripts before the actual containers start.
You can execute multiple initContainers in the same Pod, but keep in mind they will run one after another, **not** in parallel.
initContainers can have their own Docker images, so you can offload some configuration to them and keeping your main images as small as possible, increasing the security of your cluster.
Keep in mind that a pod will **not** be launched if one of the initContainers will stop. They are not to be seen as something optional or something that could fail.
### 🚀 Run the setup:
1. Create the pod:
```bash
kubectl apply -f initContainer.yml
```
2. Watch the logs:
```bash
kubectl get pods -w
```
3. See the logs for a specific container:
```bash
kubectl logs pods/nginx-with-init-container -c nginx-container
```
4. See all logs for all containers in a pod:
```bash
kubectl logs pods/nginx-with-init-container
```
5. See logs for past 2 hours in a certain container:
```bash
kubectl logs --since=2h pods/nginx-with-init-container -c nginx-container
```
6. See only the last 30 logs of a container:
```bash
kubectl logs --tail=30 pods/nginx-with-init-container -c nginx-container
```
🌎 There are many more ways to see logs, the command is pretty flexible. You can try for yourself.
### ❗️ Also, here is a useful resource I found on pod creation:
