A webserver for serving a JSON list of processes that are listening on ports.
Environment variables to configure the exporter
Name | Default | Purpose |
---|---|---|
POD_NAME | == | The name for the Pod |
APP_PORT | :10093 | The port to bind to |
APP_POD_LABELS_FILE_PATH | /etc/podlabels/labels | The path to a downward API generated file containing the labels set in metadata.labels , used for matching against when creating a Service |
An example request
curl -s http://localhost:10093/listening | jq .
will return contents like this
Note that when running in Kubernetes, the field shareProcessNamespace
in v1.Pod.Spec
must be set to true
.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: environment-dev
namespace: default
spec:
serviceName: environment-dev
replicas: 1
selector:
matchLabels:
app: environment-dev
template:
metadata:
labels:
app: environment-dev
spec:
shareProcessNamespace: true
containers:
- name: environment
image: registry.gitlab.com/sharingio/environment:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: home-ii
mountPath: /home/ii
- name: podlabels
mountPath: /etc/podlabels
command:
- sleep
- +Inf
- name: environment-exporter
image: registry.gitlab.com/sharingio/environment/exporter:latest
imagePullPolicy: IfNotPresent
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 10093
volumeMounts:
- name: podlabels
mountPath: /etc/podlabels
volumes:
- name: home-ii
hostPath:
path: /home/ii
- name: podlabels
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
Apply the manifest
kubectl apply -f ./example.yaml
The podlabels file must exist. If it does not then run the following command (when running in a Pair instance)
mkdir -p /etc/podlabels/
kubectl get pod $HOSTNAME -o=go-template='{{ range $key, $value := .metadata.labels }}{{ $key }}={{ $value}}{{ "\n" }}{{ end }}' | sudo tee /etc/podlabels/labels
Note, you can also get the same