https://github.com/s0ders/k8s-depends
Program meant to be used as an initContainers in K8S to provide a functionnality similar to the "depends_on" offered by Docker Compose.
https://github.com/s0ders/k8s-depends
dependson kubernetes
Last synced: 3 months ago
JSON representation
Program meant to be used as an initContainers in K8S to provide a functionnality similar to the "depends_on" offered by Docker Compose.
- Host: GitHub
- URL: https://github.com/s0ders/k8s-depends
- Owner: s0ders
- License: mit
- Created: 2022-07-22T09:17:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-11T09:33:05.000Z (over 1 year ago)
- Last Synced: 2026-04-25T10:36:52.320Z (3 months ago)
- Topics: dependson, kubernetes
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# K8S Depends
## Motivations
This Go program aims to give Kubernetes a similar capability that Docker Compose offers : `depends_on`. In Docker
Compose, this keyword allows to programmatically set the order in which the containers are to start.
Kubernetes does not propose this functionality as it is out of the tool's scope. Hence, this small Go program and its
Docker image offers a simple solution to make sure that containers inside a Pod will not start until the specified
Kubernetes service are alive.
The program accepts the following flags:
| Flag | Option | Default Value |
|-------------|-------------------------------------------------------------------------------|---------------|
| `--timeout` | Set the timeout in seconds for each service after which it is considered down | 60 |
| `--sleep` | Set the timeout in seconds between two consecutive polls of a given service | 1 |
The rest of the arguments passed to the program are the services in form `SERVICE_NAME:SERVICE_PORT` you want to wait for.
## Install
This program is available as a Docker image and is hosted on Docker Hub:
```bash
$ docker pull s0ders/k8s-depends
```
## Examples
```yaml
apiVersion: v1
kind: Pod
metadata:
name: hello_world
spec:
# Image is used as an initContainers to prevent containers from starting
# before the given services are up and running.
initContainers:
- name: depends
image: s0ders/depends
args: ["--timeout=120", "database-svc:5432", "cache-svc:6379"]
containers:
- name: web_server
image: nginx
```
To check the logs of your "depends" `initContainers` you can use the following `kubectl` command:
```bash
kubectl logs -c
```