Public | Automated Build

Last pushed: 2 years ago
Short Description
sidecar container for kubernetes to expose various meta-data of the running pod
Full Description

Kubernetes podmeta

Sidecar container that exposes meta-data of the running pod as files.

It collects its data from the kubernetes downward API, the kubernetes API and the docker API (optional).

Exposed files in /var/run/podmeta/

  • node_name
  • pod_name
  • pod_namespace
  • pod_uid
  • pod_metadata.json
  • container_id
  • container_metadata.json (optional)
  • container_binds (optional)

Use cases

In a way this extends the kubernetes downward API with additional info. Note this is an anti-pattern. Normally applications should not need to know they are running in a container or POD. Using this may trick you into unwanted couplings with the system.

However there are a few use cases where it can be useful:

  • you are logging to a central place and want to tag the node hostname
  • you want to know the path on the host of hostMounts to hack around, e.g. re-use the mounts in some other docker container manually launched from the POD.

How to use it

You do not need to modify your application docker image. Just add a new container to your pod.

You must pass these environment variables to new the podmeta container using the downward API:

- env:
    - name: POD_NAME
      valueFrom:
        fieldRef: {fieldPath: metadata.name}
    - name: POD_NAMESPACE
      valueFrom:
        fieldRef: {fieldPath: metadata.namespace}

If you want to re-use the data in other containers in the POD, make sure you mount the podmeta volume in both the podmeta and your app container and the metadata files can be accesses seamlessly.

volumeMounts:
- {mountPath: /var/run/podmeta, name: podmeta}

Mounting the docker socket is optional. If you do, metadata of the podmeta container will also be dumped.

Although it is not done in the example below, make sure to wait for the file you need to be there before using it as containers may start in random order.

Example

Use this pod to test: example

curl -O https://raw.githubusercontent.com/bidibi/kubernetes-podmeta/master/demo-podmeta.yaml
kubectl create -f demo-podmeta.yaml
# wait for pod to be Running
kubectl logs demo-podmeta -c your-own-container

Docker image

The image is about 12 Mb. There is an automated build here or you can build it yourself with 'make image'

Docker Pull Command
Owner
bidibi
Source Repository