Hi
I want heartbeat to find every single kubernetes pod and send it to Elasticsearch uptime, however all I am able to currently get is the kubernetes nodes. Below is the config.
apiVersion: v1
kind: ConfigMap
metadata:
name: heartbeat-deployment-config
namespace: elk
labels:
k8s-app: heartbeat
data:
heartbeat.yml: |-
heartbeat.autodiscover:
# Autodiscover pods
providers:
- type: kubernetes
resource: pod
scope: cluster
node: ${NODE_NAME}
hints.enabled: true
templates:
- condition: ~
#contains:
# kubernetes.container.image: nginx
# #kubernetes.labels.heartbeat_type: http
config:
- type: http
hosts: ["${data.host}:${data.port}"]
name: ${data.kubernetes.pod.name}
schedule: '@every 1s'
timeout: 2s
# Autodiscover services
providers:
- type: kubernetes
resource: service
scope: cluster
node: ${NODE_NAME}
hints.enabled: true
# # Autodiscover nodes
providers:
- type: kubernetes
resource: node
node: ${NODE_NAME}
scope: cluster
templates:
# Example, check SSH port of all cluster nodes:
- condition: ~
config:
- hosts:
- ${data.host}:22
name: ${data.kubernetes.node.name}
schedule: '@every 10s'
timeout: 5s
type: tcp
processors:
- add_cloud_metadata:
cloud.id: ${ELASTIC_CLOUD_ID}
cloud.auth: ${ELASTIC_CLOUD_AUTH}
output.elasticsearch:
hosts: ['https://x.x.x.x:9200']
username: elastic
password: itss@123
ssl.certificate_authorities:
- /etc/certs/ssl/ca.crt
---
# Deploy singleton instance in the whole cluster for some unique data sources, like kube-state-metrics
apiVersion: apps/v1
kind: Deployment
metadata:
name: heartbeat
namespace: elk
labels:
k8s-app: heartbeat
spec:
selector:
matchLabels:
k8s-app: heartbeat
template:
metadata:
labels:
k8s-app: heartbeat
spec:
serviceAccountName: heartbeat
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: heartbeat
image: docker.elastic.co/beats/heartbeat:7.15.2
args: [
"-c", "/etc/heartbeat.yml",
"-e",
]
env:
- name: ELASTICSEARCH_HOST
value: elasticsearch
- name: ELASTICSEARCH_PORT
value: "9200"
- name: ELASTICSEARCH_USERNAME
value: elastic
- name: ELASTICSEARCH_PASSWORD
value: itss@123
- name: ELASTIC_CLOUD_ID
value:
- name: ELASTIC_CLOUD_AUTH
value:
#- name: cert
#mountPath: /etc/certs/ssl/ca.crt
#readOnly: true
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
securityContext:
runAsUser: 0
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: config
mountPath: /etc/heartbeat.yml
readOnly: true
subPath: heartbeat.yml
- name: data
mountPath: /usr/share/heartbeat/data
- name: cert
mountPath: /etc/certs/ssl/ca.crt
readOnly: true
subPath: ca.crt
volumes:
- name: config
configMap:
defaultMode: 0600
name: heartbeat-deployment-config
- name: data
hostPath:
path: /var/lib/heartbeat-data
type: DirectoryOrCreate
- name: cert
secret:
secretName: my-tls-secret
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: heartbeat
namespace: elk
roleRef:
kind: ClusterRole
name: heartbeat
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: heartbeat
namespace: elk
subjects:
- kind: ServiceAccount
name: heartbeat
namespace: elk
roleRef:
kind: Role
name: heartbeat
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: heartbeat-kubeadm-config
namespace: elk
subjects:
- kind: ServiceAccount
name: heartbeat
namespace: elk
roleRef:
kind: Role
name: heartbeat-kubeadm-config
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: heartbeat
labels:
k8s-app: heartbeat
rules:
- apiGroups: [""]
resources:
- nodes
- namespaces
- pods
- services
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources:
- replicasets
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: heartbeat
# should be the namespace where heartbeat is running
namespace: elk
labels:
k8s-app: heartbeat
rules:
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs: ["get", "create", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: heartbeat-kubeadm-config
namespace: elk
labels:
k8s-app: heartbeat
rules:
- apiGroups: [""]
resources:
- configmaps
resourceNames:
- kubeadm-config
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: heartbeat
namespace: elk
labels:
k8s-app: heartbeat
---