Skip to content

s0ders/k8s-depends

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K8S Depends

GitHub go.mod Go version GitHub Actions Workflow Status Go Report Card GitHub License

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:

$ docker pull s0ders/k8s-depends

Examples

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:

kubectl logs <pod_name> -c <init_container_name>

About

Program meant to be used as an initContainers in K8S to provide a functionnality similar to the "depends_on" offered by Docker Compose.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors