项目作者: bloomberg

项目描述 :
Debugging tool for Kubernetes which tests and displays connectivity between nodes in the cluster.
高级语言: JavaScript
项目地址: git://github.com/bloomberg/goldpinger.git
创建时间: 2018-12-04T18:31:10Z
项目社区:https://github.com/bloomberg/goldpinger

开源协议:Apache License 2.0

下载


Goldpinger

Publish

Goldpinger makes calls between its instances to monitor your networking.
It runs as a DaemonSet on Kubernetes and produces Prometheus metrics that can be scraped, visualised and alerted on.

Oh, and it gives you the graph below for your cluster. Check out the video explainer.

:tada: 1M+ pulls from docker hub!

On the menu

Rationale

We built Goldpinger to troubleshoot, visualise and alert on our networking layer while adopting Kubernetes at Bloomberg. It has since become the go-to tool to see connectivity and slowness issues.

It’s small (~16MB), simple and you’ll wonder why you hadn’t had it before.

If you’d like to know more, you can watch our presentation at Kubecon 2018 Seattle.

Quick start

Getting from sources:

  1. go get github.com/bloomberg/goldpinger/cmd/goldpinger
  2. goldpinger --help

Getting from docker hub:

  1. # get from docker hub
  2. docker pull bloomberg/goldpinger:v3.0.0

Building

The repo comes with two ways of building a docker image: compiling locally, and compiling using a multi-stage Dockerfile image. :warning: Depending on your docker setup, you might need to prepend the commands below with sudo.

Compiling using a multi-stage Dockerfile

You will need docker version 17.05+ installed to support multi-stage builds.

  1. # Build a local container without publishing
  2. make build
  3. # Build & push the image somewhere
  4. namespace="docker.io/myhandle/" make build-release

This was contributed via @michiel - kudos !

Compiling locally

In order to build Goldpinger, you are going to need go version 1.15+ and docker.

Building from source code consists of compiling the binary and building a Docker image:

  1. # step 0: check out the code
  2. git clone https://github.com/bloomberg/goldpinger.git
  3. cd goldpinger
  4. # step 1: compile the binary for the desired architecture
  5. make bin/goldpinger
  6. # at this stage you should be able to run the binary
  7. ./bin/goldpinger --help
  8. # step 2: build the docker image containing the binary
  9. namespace="docker.io/myhandle/" make build
  10. # step 3: push the image somewhere
  11. docker push $(namespace="docker.io/myhandle/" make version)

Installation

Goldpinger works by asking Kubernetes for pods with particular labels (app=goldpinger). While you can deploy Goldpinger in a variety of ways, it works very nicely as a DaemonSet out of the box.

Helm Installation

Goldpinger can be installed via Helm using the following:

  1. helm repo add goldpinger https://bloomberg.github.io/goldpinger
  2. helm repo update
  3. helm install goldpinger goldpinger/goldpinger

Manual Installation

Goldpinger can be installed manually via configuration similar to the following:

Authentication with Kubernetes API

Goldpinger supports using a kubeconfig (specify with --kubeconfig-path) or service accounts.

Example YAML

Here’s an example of what you can do (using the in-cluster authentication to Kubernetes apiserver).

  1. ---
  2. apiVersion: v1
  3. kind: ServiceAccount
  4. metadata:
  5. name: goldpinger-serviceaccount
  6. namespace: default
  7. ---
  8. apiVersion: apps/v1
  9. kind: DaemonSet
  10. metadata:
  11. name: goldpinger
  12. namespace: default
  13. labels:
  14. app: goldpinger
  15. spec:
  16. updateStrategy:
  17. type: RollingUpdate
  18. selector:
  19. matchLabels:
  20. app: goldpinger
  21. template:
  22. metadata:
  23. annotations:
  24. prometheus.io/scrape: 'true'
  25. prometheus.io/port: '8080'
  26. labels:
  27. app: goldpinger
  28. spec:
  29. serviceAccount: goldpinger-serviceaccount
  30. tolerations:
  31. - key: node-role.kubernetes.io/master
  32. effect: NoSchedule
  33. securityContext:
  34. runAsNonRoot: true
  35. runAsUser: 1000
  36. fsGroup: 2000
  37. containers:
  38. - name: goldpinger
  39. env:
  40. - name: HOST
  41. value: "0.0.0.0"
  42. - name: PORT
  43. value: "8080"
  44. # injecting real hostname will make for easier to understand graphs/metrics
  45. - name: HOSTNAME
  46. valueFrom:
  47. fieldRef:
  48. fieldPath: spec.nodeName
  49. # podIP is used to select a randomized subset of nodes to ping.
  50. - name: POD_IP
  51. valueFrom:
  52. fieldRef:
  53. fieldPath: status.podIP
  54. image: "docker.io/bloomberg/goldpinger:v3.0.0"
  55. imagePullPolicy: Always
  56. securityContext:
  57. allowPrivilegeEscalation: false
  58. readOnlyRootFilesystem: true
  59. resources:
  60. limits:
  61. memory: 80Mi
  62. requests:
  63. cpu: 1m
  64. memory: 40Mi
  65. ports:
  66. - containerPort: 8080
  67. name: http
  68. readinessProbe:
  69. httpGet:
  70. path: /healthz
  71. port: 8080
  72. initialDelaySeconds: 20
  73. periodSeconds: 5
  74. livenessProbe:
  75. httpGet:
  76. path: /healthz
  77. port: 8080
  78. initialDelaySeconds: 20
  79. periodSeconds: 5
  80. ---
  81. apiVersion: v1
  82. kind: Service
  83. metadata:
  84. name: goldpinger
  85. namespace: default
  86. labels:
  87. app: goldpinger
  88. spec:
  89. type: NodePort
  90. ports:
  91. - port: 8080
  92. nodePort: 30080
  93. name: http
  94. selector:
  95. app: goldpinger

Note, that you will also need to add an RBAC rule to allow Goldpinger to list other pods. If you’re just playing around, you can consider a view-all default rule:

  1. ---
  2. apiVersion: rbac.authorization.k8s.io/v1
  3. kind: ClusterRoleBinding
  4. metadata:
  5. name: default
  6. roleRef:
  7. apiGroup: rbac.authorization.k8s.io
  8. kind: ClusterRole
  9. name: view
  10. subjects:
  11. - kind: ServiceAccount
  12. name: goldpinger-serviceaccount
  13. namespace: default

You can also see an example of using kubeconfig in the ./extras.

Using with IPv4/IPv6 dual-stack

If your cluster IPv4/IPv6 dual-stack and you want to force IPv6, you can set the IP_VERSIONS environment variable to “6” (default is “4”) which will use the IPv6 address on the pod and host.

ipv6

Note on DNS

Note, that on top of resolving the other pods, all instances can also try to resolve arbitrary DNS. This allows you to test your DNS setup.

From --help:

  1. --host-to-resolve= A host to attempt dns resolve on (space delimited) [$HOSTS_TO_RESOLVE]

So in order to test two domains, we could add an extra env var to the example above:

  1. - name: HOSTS_TO_RESOLVE
  2. value: "www.bloomberg.com one.two.three"

and goldpinger should show something like this:

screenshot-DNS-resolution

TCP and HTTP checks to external targets

Instances can also be configured to do simple TCP or HTTP checks on external targets. This is useful for visualizing more nuanced connectivity flows.

  1. --tcp-targets= A list of external targets(<host>:<port> or <ip>:<port>) to attempt a TCP check on (space delimited) [$TCP_TARGETS]
  2. --http-targets= A list of external targets(<http or https>://<url>) to attempt an HTTP{S} check on. A 200 HTTP code is considered successful. (space delimited) [$HTTP_TARGETS]
  3. --tcp-targets-timeout= The timeout for a tcp check on the provided tcp-targets (default: 500) [$TCP_TARGETS_TIMEOUT]
  4. --dns-targets-timeout= The timeout for a tcp check on the provided udp-targets (default: 500) [$DNS_TARGETS_TIMEOUT]
  1. - name: HTTP_TARGETS
  2. value: http://bloomberg.com
  3. - name: TCP_TARGETS
  4. value: 10.34.5.141:5000 10.34.195.193:6442

the timeouts for the TCP, DNS and HTTP checks can be configured via TCP_TARGETS_TIMEOUT, DNS_TARGETS_TIMEOUT and HTTP_TARGETS_TIMEOUT respectively.

screenshot-tcp-http-checks

Usage

UI

Once you have it running, you can hit any of the nodes (port 30080 in the example above) and see the UI.

You can click on various nodes to gray out the clutter and see more information.

API

The API exposed is via a well-defined Swagger spec.

The spec is used to generate both the server and the client of Goldpinger. If you make changes, you can re-generate them using go-swagger via make swagger

Prometheus

Once running, Goldpinger exposes Prometheus metrics at /metrics. All the metrics are prefixed with goldpinger_ for easy identification.

You can see the metrics by doing a curl http://$POD_ID:80/metrics.

These are probably the droids you are looking for:

  1. goldpinger_peers_response_time_s_*
  2. goldpinger_peers_response_time_s_*
  3. goldpinger_nodes_health_total
  4. goldpinger_stats_total
  5. goldpinger_errors_total

Grafana

You can find an example of a Grafana dashboard that shows what’s going on in your cluster in extras. This should get you started, and once you’re on the roll, why not :heart: contribute some kickass dashboards for others to use ?

Alert Manager

Once you’ve gotten your metrics into Prometheus, you have all you need to set useful alerts.

To get you started, here’s a rule that will trigger an alert if there are any nodes reported as unhealthy by any instance of Goldpinger.

  1. alert: goldpinger_nodes_unhealthy
  2. expr: sum(goldpinger_nodes_health_total{status="unhealthy"})
  3. BY (instance, goldpinger_instance) > 0
  4. for: 5m
  5. annotations:
  6. description: |
  7. Goldpinger instance {{ $labels.goldpinger_instance }} has been reporting unhealthy nodes for at least 5 minutes.
  8. summary: Instance {{ $labels.instance }} down

Similarly, why not :heart: contribute some amazing alerts for others to use ?

Chaos Engineering

Goldpinger also makes for a pretty good monitoring tool in when practicing Chaos Engineering. Check out PowerfulSeal, if you’d like to do some Chaos Engineering for Kubernetes.

Authors

Goldpinger was created by Mikolaj Pawlikowski and ported to Go by Chris Green.

Contributions

We :heart: contributions.

Have you had a good experience with Goldpinger ? Why not share some love and contribute code, dashboards and alerts ?

If you’re thinking of making some code changes, please be aware that most of the code is auto-generated from the Swagger spec. The spec is used to generate both the server and the client of Goldpinger. If you make changes, you can re-generate them using go-swagger via make swagger.

Before you create that PR, please make sure you read CONTRIBUTING and DCO.

License

Please read the LICENSE file here.

For each version built by travis, there is also an additional version, appended with -vendor, which contains all source code of the dependencies used in goldpinger.