-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
document running prometheus server in kubernetes
- Loading branch information
1 parent
94081dd
commit b308e9c
Showing
4 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Example Kubernetes Manifests | ||
|
||
This folder provides two example Kubernetes manifests: | ||
* [shellyctl-prom-hostNetwork.yaml](shellyctl-prom-hostNetwork.yaml) - Configures a prometheus server with mDNS search enabled on all interfaces. To support mDNS discovery this pod MUST run with `hostNetwork: true` which enables additional network privileges. To avoid port-conficts during pod replacement, the server is run as a StatefulSet w/ 1 replica. | ||
* [shellyctl-prom.yaml](shellyctl-prom.yaml) - Configures a prometheus server running within pod networking. This leverages a traditional Deployment model. Because no mDNS/BLEdiscovery is possible you MUST specify hosts in the config file or configure and MQTT server. | ||
|
||
## Updating configuration | ||
Both variants leverage a config-map for configuring shellyctl flags. Shellyctl does NOT support live config reloading so you must restar or replace the pod to reload configuration. | ||
|
||
``` | ||
# edit the config file. | ||
kubectl edit -n shellyctl configmap shellyctl-prom | ||
# replace shellyctl pods to reload configuration | ||
kubectl delete pod -n shellyctl --all | ||
``` | ||
|
||
## Service Discovery | ||
These examples use the `prometheus.io/scrape` and `prometheus.io/port` anotations for service discovery. Your prometheus service discovery may be configured differently. See: | ||
* [Prometheus Service Discovery Configuration](https://prometheus.io/docs/prometheus/latest/configuration/configuration/) | ||
* [PodMonitor/ServiceMonitor in Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/getting-started.md#deploying-a-sample-application) | ||
* [Victoria Metrics Agent](https://docs.victoriametrics.com/vmagent/) | ||
|
||
|
||
## shellyctl-prom-hostNetwork.yaml | ||
``` | ||
# Create a namespace, shellyctl. | ||
kubectl create namespace shellyctl | ||
# Optionally add a password for authenticating with devices. This step may be skipped if you do not use auth. | ||
kubectl create secret -n shellyctl generic shellyctl-auth --from-literal=SHELLYCTL_AUTH=password | ||
# Apply the manifest. | ||
kubectl apply -f https://raw.githubusercontent.com/jcodybaker/shellyctl/main/contrib/k8s/shellyctl-prom-hostNetwork.yaml | ||
``` | ||
|
||
## shellyctl-prom.yaml | ||
``` | ||
# Create a namespace, shellyctl. | ||
kubectl create namespace shellyctl | ||
# Optionally add a password for authenticating with devices. This step may be skipped if you do not use auth. | ||
kubectl create secret -n shellyctl generic shellyctl-auth --from-literal=SHELLYCTL_AUTH=password | ||
# Download the manifest for local editing. | ||
curl -LfO https://raw.githubusercontent.com/jcodybaker/shellyctl/main/contrib/k8s/shellyctl-prom.yaml | ||
# Edit the `host` list in configmap. | ||
editor shellyctl-prom.yaml | ||
# Apply the manifest. | ||
kubectl apply -f shellyctl-prom.yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
labels: | ||
kubernetes.io/metadata.name: shellyctl | ||
name: shellyctl | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: shellyctl-prom | ||
namespace: shellyctl | ||
data: | ||
shellyctl-prom.yaml: | | ||
bind-port: 9090 | ||
log-level: debug | ||
host: | ||
# Example host config with password. | ||
- http://admin:[email protected] | ||
- http://127.0.0.1 | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: shellyctl-prom | ||
name: shellyctl-prom | ||
namespace: shellyctl | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: shellyctl-prom | ||
template: | ||
metadata: | ||
labels: | ||
app: shellyctl-prom | ||
spec: | ||
containers: | ||
- command: | ||
- /bin/shellyctl | ||
- prometheus | ||
env: | ||
- name: SHELLYCTL_CONFIG | ||
value: /run/shellyctl/shellyctl-prom.yaml | ||
image: ghcr.io/jcodybaker/shellyctl:latest | ||
imagePullPolicy: Always | ||
name: shellyctl | ||
ports: | ||
- containerPort: 9090 | ||
protocol: TCP | ||
volumeMounts: | ||
- mountPath: /run/shellyctl | ||
name: config | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: Always | ||
terminationGracePeriodSeconds: 30 | ||
volumes: | ||
- configMap: | ||
defaultMode: 420 | ||
name: shellyctl-prom | ||
name: config | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: shellyctl-prom | ||
annotations: | ||
prometheus.io/port: "9090" | ||
prometheus.io/scrape: "true" | ||
name: shellyctl-prom | ||
namespace: shellyctl | ||
spec: | ||
ports: | ||
- name: 9090-9090 | ||
port: 9090 | ||
protocol: TCP | ||
targetPort: 9090 | ||
selector: | ||
app: shellyctl-prom | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters