Code Monkey home page Code Monkey logo

stakater / ingressmonitorcontroller Goto Github PK

View Code? Open in Web Editor NEW
578.0 12.0 102.0 72.18 MB

A Kubernetes controller to watch ingresses and create liveness alerts for your apps/microservices in UptimeRobot, StatusCake, Pingdom, etc. – [✩Star] if you're using it!

Home Page: https://stakater.com

License: Apache License 2.0

Go 94.68% Makefile 3.83% Dockerfile 0.66% Smarty 0.83%
kubernetes stakater ingress controller k8s monitor uptime-checker live isup uptimerobot

ingressmonitorcontroller's Introduction

imc-logo Ingress Monitor Controller

An operator to watch ingresses/routes and create liveness alerts for your apps/microservices in Uptime checkers.

Get started with Stakater

Problem Statement

We want to monitor ingresses in a kubernetes cluster and routes in openshift cluster via any uptime checker but the problem is having to manually check for new ingresses or routes / removed ingresses or routes and add them to the checker or remove them.

Solution

This operator will continuously watch ingresses/routes based on defined EndpointMonitor custom resource, and automatically add / remove monitors in any of the uptime checkers. With the help of this solution, you can keep a check on your services and see whether they're up and running and live, without worrying about manually registering them on the Uptime checker.

Supported Uptime Checkers

Currently we support the following monitors:

Usage

Adding configuration

Configure the uptime checker configuration in the config.yaml based on your uptime provider. Add create a secret imc-config that holds config.yaml key:

kind: Secret
apiVersion: v1
metadata:
  name: imc-config
data:
  config.yaml: >-
    <BASE64_ENCODED_CONFIG.YAML>
type: Opaque

Configuration Parameters

Following are the available options that you can use to customize the controller:

Key Description
providers An array of uptime providers that you want to add to your controller
enableMonitorDeletion A safeguard flag that is used to enable or disable monitor deletion on ingress deletion (Useful for prod environments where you don't want to remove monitor on ingress deletion)
resyncPeriod Resync period in seconds, allows to re-sync periodically the monitors with the Routes. Defaults to 0 (= disabled)
creationDelay CreationDelay is a duration string to add a delay before creating new monitor (e.g., to allow DNS to catch up first)
monitorNameTemplate Template for monitor name eg, {{.Namespace}}-{{.Name}}
  • Replace BASE64_ENCODED_CONFIG.YAML with your config.yaml file that is encoded in base64.
  • For detailed guide for the configuration refer to Docs and go through configuration guidelines for your uptime provider.
  • For sample config.yaml files refer to Sample Configs.
  • Name of secret can be changed by setting environment variable CONFIG_SECRET_NAME.

Add EndpointMonitor

EndpointMonitor resource can be used to manage monitors on static urls or route/ingress references.

  • Specifying url:
apiVersion: endpointmonitor.stakater.com/v1alpha1
kind: EndpointMonitor
metadata:
  name: stakater
spec:
  forceHttps: true
  url: https://stakater.com
  • Specifying route reference:
apiVersion: endpointmonitor.stakater.com/v1alpha1
kind: EndpointMonitor
metadata:
  name: frontend
spec:
  forceHttps: true
  urlFrom:
    routeRef:
      name: frontend
  • Specifying ingress reference:
apiVersion: endpointmonitor.stakater.com/v1alpha1
kind: EndpointMonitor
metadata:
  name: frontend
spec:
  forceHttps: true
  urlFrom:
    ingressRef:
      name: frontend

NOTE: For provider specific additional configuration refer to Docs and go through configuration guidelines for your uptime provider.

Deploying the Operator

The following quickstart let's you set up Ingress Monitor Controller to register uptime monitors for endpoints:

Helm Chart

If you have configured helm on your cluster, you can deploy IngressMonitorController via helm using below mentioned commands. For details on chart, see IMC Helm Chart

# Install CRDs
kubectl apply -f https://raw.githubusercontent.com/stakater/IngressMonitorController/master/charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml

# Install chart
helm repo add stakater https://stakater.github.io/stakater-charts

helm repo update

helm install stakater/ingressmonitorcontroller

Vanilla Manifests

  1. Clone this repository
    $ git clone [email protected]:stakater/IngressMonitorController.git
  1. Deploy dependencies(crds):
    $ make deploy

Environment Variables

Key Default Description
WATCH_NAMESPACE Namespace in which operator is deployed Use comma separated list of namespaces or leave the field empty to watch all namespaces(cluster scope)
CONFIG_SECRET_NAME imc-config Name of secret that holds the configuration
REQUEUE_TIME 300 seconds Integer value to specify number of seconds after which the resource should be reconciled again

Help

Documentation

You can find more detailed documentation for configuration, extension, and support for other Uptime checkers etc. here

Contributing

If you'd like to contribute any fixes or enhancements, please refer to the documentation here

Have a question?

File a GitHub issue.

Talk to us on Slack

Join and talk to us on the #tools-ingressmonitor channel for discussing the Ingress Monitor Controller

Join Slack Chat

Known Issues

  • Latest image of kube-rbac-proxy fails on openshift with permission issues. To resolve use registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.7.0 instead of kube-rbac-proxy. This issue can be tracked here.

License

Apache2 © Stakater

About

The IngressMonitorController is maintained by Stakater. Like it? Please let us know at [email protected]

See our other projects or contact us in case of professional services and queries on [email protected]

Contributors

Stakater Team and the Open Source community! 🏆

ingressmonitorcontroller's People

Contributors

abdulhaseeb2 avatar ahmedwaleedmalik avatar ahsan-storm avatar alandotcom avatar aliartiza75 avatar anish-gupta-bose avatar artemlive avatar bnallapeta avatar daveshepherd avatar faizanahmad055 avatar gempesaw avatar hazim1093 avatar hussnain612 avatar jess-belliveau avatar kahootali avatar karl-johan-grahn avatar karlderkaefer avatar lilshah avatar muneebaijaz avatar muneebstakater avatar nohant avatar rasheedamir avatar renovate[bot] avatar stakater-user avatar tanalam2411 avatar thunef avatar tuananhnguyen-ct avatar twardnw avatar usamaahmadkhan avatar waseem-h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ingressmonitorcontroller's Issues

Ingress wrapper is building wrong urls in case there is a named servicePort in ingress

Hello there, Ingress builder code is creating wrong monitor url in case there is a named servicePort in ingress.yaml and the path is set as "/*". Basically in the ingress_wrapper.go between L63-L80 is checking for the servicePort in ingress.yaml and adding the servicePort into the monitorURL path, which doesn't look right.

My ingress.yaml looks like this:

kind: Ingress
metadata:
  annotations:
    alb.ingress.kubernetes.io/healthcheck-path: /healthz
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/security-groups: sg-438f8633
    alb.ingress.kubernetes.io/subnets: subnet-d30c46aa, subnet-b1becafa, subnet-81cce9db
    external-dns.alpha.kubernetes.io/hostname: abc.example.com
    kubernetes.io/ingress.class: alb
    monitor.stakater.com/enabled: "true"
  generation: 2
  labels:
    app: reviewfunnel
    chart: reviewfunnel-0.1.0
    cleanup: "true"
    deployed-with: skaffold
    docker-api-version: "1.39"
    heritage: Tiller
    release: stg-reviewfunnel
    skaffold-builder: local
    skaffold-deployer: helm
    skaffold-tag-policy: sha256
  name: stg-reviewfunnel
  namespace: staging
spec:
  rules:
  - host: abc.example.com
    http:
      paths:
      - backend:
          serviceName: stg-reviewfunnel-app
          servicePort: http
        path: /*

So the monitorURL looks like this
2018/11/21 12:08:38 Monitor URL: http://abc.exmaple.com/http/%2A

Which should be http://abc.example.com/ and when the ingressMonitor service sends a get request, it should return a 200 status code as it's up.

I have raised a PR to fix this issue. The link to the PR is: https://github.com/stakater/IngressMonitorController/pull/132.

Kindly review the PR and let me know about your thoughts

Add pingdom support

Saw the Medium article, great tool!

We use Pingdom, which also has a decent API (though a fair bit different from the UptimeRobot API).

If this isn't already in the works, I'll have a crack at it 😄 - seems like there might be some changes needed to the httpClient layer to make it happen.

Fix pingdom annotations

Currently pingdom annotation are in format monitor.stakater.com/pingdom/annotation but this format is not allowed in kubernetes. We have to update the current pingdom annotations to the following format

monitor-name.monitor.stakater.com/annotation

i.e., pingdom.monitor.stakater.com/annotation

overridePath escaping

Using the annotation monitor.stakater.com/overridePath with characters like ? currently automatically escapes them: e.g. /health?apikey=test becomes /health%3Fapikey=test and is inserted like this in UptimeRobot monitors.

Typical log output:

Monitor Name: test
Monitor URL: https://test.example.com/health%3Fpwd=test
Monitor Added: test

Is there a way to work around this?

K8S objects created during tests fail on simultaneous runs

IMC creates several k8s objects while running its tests, and simultaneous tests running causes conflicts as the name of the objects is same.

Append a unique identifier with k8s objects created during tests so that there is no conflict while running multiple pipelines/tests simultaneously.

Add support for Azure Application Insights in IMC

Add helm-chart deployments to the Makefile

As suggested by @Anish-Gupta-Bose it will be good to add helm-chart deployments to the Makefile:

helm-template:
	helm template kubernetes/chart/ingressmonitorcontroller --values $(HELMVALUES) --name $(HELMNAME)

helm-install:
	helm install kubernetes/chart/ingressmonitorcontroller --values $(HELMVALUES) --name $(HELMNAME)

Refactor configmap to secrets

Currently we take passwords and api keys as plain configmaps whereas they should be secrets.

Tasks:

  • Refactor to convert them to secrets
  • Update deployments and examples
  • Update readme that its a breaking change and now info should be provided as a secret and not a configmap

Add support for Stackdriver Uptime Checks and Alert Policies in IMC

Specify the strategy for update in manifests

We must include the udpate strategy by default in all of the manifests e.g.

  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate

Also how many replica's should be run?

Handle per service monitoring

Hi there, I have a follow use case - have Ingress controller installed and below is its sample resource file:

annotations:
   kubernetes.io/ingress.class: "nginx"
   monitor.stakater.com/enabled: "true"
Spec:
rules:
  - host: helloworld.awesome-customer.com
    http:
    paths:
    - path: /*
    backend:
    serviceName: helloworld
    servicePort: 8080
  - host: nextfineapp.awesome-customer.com
    http:
    paths:
    - path: /*
    backend:
    serviceName: nextfineapp
    servicePort: 8080

I would like to configure IMC with Pingdom as service provider. In this case IMC will monitor this particular Ingress controller. However, what I need is to receive notification in case particular service is down. So I need per service notification. How can I achieve that?

RBAC: Cluster role vs per-namespace role

Would you accept a PR with a ClusterRole instead of the current Role, or an option to chose between the two in the helm release?

Our use case is that we have a tooling namespace for all controllers and do not duplicate those controllers for each namespace.

Change operator work queue to a map of *Ingress object

Suggestion from @Mikulas

Refactor the code; namely the operator work queue would be easier to work with if it was in fact a map with the *Ingress object. It would also simplify the code as it would remove the parsing (splitting) of the namespace/name key and would eliminate the API calls for getting an Ingress from key (name).

Use constants for statusCodes

Currently, hard code values for the status code are being used like 200 and 404 etc, which is not easy to understand(for beginners) and error-prone(because we might need to updated all files for a single status code change).

OLD SOLUTION

Instead of hard code values, constants must be used. A map has been defined in the pkg/constants that contains the constants for status codes.

filename: httpStatusCodesMap.go

var StatusCodes = map[string]int{
	"OK":            200,
	"NOT_FOUND":     404,
	"UN_AUTHORISED": 401,
	"BAD_REQUEST":   400,
	"CREATED":       201}

NEW SOLUTION

Based on @waseem-h suggestion, go's net/http package constants will be used for response codes.

This change must be applied to all IMC modules.

Add support for basic auth (uptimerobot.com)

uptimerobot.com supports adding basic auth (http_username & http_password) to monitors. It would be nice, if IngressMonitorController could set those settings via related Ingress annotations/secrets.

configuring monitor URL construction

Howdy! Thanks for putting this controller together, it exactly solves the problem I'm working on at $WORK, so I'm quite grateful for all your hard work. I've noticed a few issues in our use case with the way the monitor URL is constructed, and I'd be happy to open PRs for either of these if you're interested.

If you're interested in accepting PRs for customizing these, I imagine they could be top level options in the config map, or per-resource annotation overrides, depending on how you'd prefer to handle the options. And, if you're not interested in accepting incidental complexity, then no problem - we'll fork and go on our merry way. Thanks again!

Monitor not deleted upon removing Ingress

Kubernetes Version: 1.10.8
Ingress Monitor Controller Version: 1.0.26
Provider: Uptime Robot

Deleted a service and ingress with IMC annotation, but it did not delete the monitor in Uptime Robot.
The logs for IMC were as follows:

2018/11/05 12:38:24 Get service from kubernetes cluster error:services "example-ws" not found
2018/11/05 12:38:24 Monitor Name: prod-example-ws
2018/11/05 12:38:24 Monitor URL: https://example.com/public/example/0.1
2018/11/05 12:38:24 Monitor already exists for ingress: prod-example-ws
2018/11/05 12:38:24 Monitor Updated: prod-example-ws

Improve the readability of ReadMe

Couple of things are misleading/confusing in the README:

  • it must clearly specify that IMC can be run per namespace or globally
  • user doesn't need to download the repo; rather just run with -f and provide file path's
  • separate the installation with vanilla manifests and helm charts in more cleaner way

IngressMonitorController should update URL on pod changes

Currently, it seems that IngressMonitorController discovers the URLs to be monitored only at startup or on Ingress changes.

If the readiness URLs of the pods behind a ingress changes, the URLs are not updated automatically.

The issue could be solved by doing regularly a full-scan of all monitors and update the URLs if necessary.
My suggestion would be to try simply a resyncPeriod > 0 in

indexer, informer := cache.NewIndexerInformer(ingressListWatcher, kube.ResourceMap[resource], 0, cache.ResourceEventHandlerFuncs{

Lean README

  • Make the README very lean, and move everything else to documentation
  • Fix banner

Create combined k8s manifest with all objects

To simplify the installation of IMC there should be one k8s manifests which includes all k8s resources/objects i.e. rbac, configmap, deployment and name it imc.

And then add in README how the user can just use that one manifest to install IMC

Monitor Produces Duplicates

I'm trying out IngressMonitorController with StatusCake for my K8s cluster.

It appears that oftentimes an ingress entity is created, it is processed twice by the monitor, resulting in two identical tests being added to StatusCake.

I'm using Kubernetes Server v1.11.3

There does appear to be an error in the log when this occurs:

2018/10/09 16:11:55 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:11:56 Monitor Added: 3534589
2018/10/09 16:11:56 Monitor Name: jnf-app1
2018/10/09 16:11:56 Monitor URL: https://test-jnf-app1.testdomain.com/app_status
2018/10/09 16:11:56 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:11:57 Monitor Added: 3534590
2018/10/09 16:11:57 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:11:57 Cannot find monitor with name: jnf-app2
2018/10/09 16:11:57 Monitor Name: jnf-app2
2018/10/09 16:11:57 Monitor URL: https://test-jnf-app2.testdomain.com/app_status
2018/10/09 16:11:57 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:11:58 Monitor Added: 3534591
2018/10/09 16:11:58 Monitor Name: jnf-app2
2018/10/09 16:11:58 Monitor URL: https://test-jnf-app2.testdomain.com/app_status
2018/10/09 16:11:59 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:11:59 Monitor Added: 3534592
2018/10/09 16:13:00 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:13:00 Cannot find monitor with name: testdomain-projects
2018/10/09 16:13:24 Monitor Name: projects
2018/10/09 16:13:24 Monitor URL: https://test-projects.testdomain.com/app_status
2018/10/09 16:13:25 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:13:26 Monitor Added: 3534595
2018/10/09 16:13:28 Monitor Name: projects
2018/10/09 16:13:28 Monitor URL: https://test-projects.testdomain.com/app_status
2018/10/09 16:13:28 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:13:29 Monitor Added: 3534596
2018/10/09 16:15:11 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:15:11 Cannot find monitor with name: jnf-app2
2018/10/09 16:15:44 Monitor Name: jnf-app2
2018/10/09 16:15:44 Monitor URL: https://test-jnf-app2.testdomain.com/app_status
2018/10/09 16:15:45 json: cannot unmarshal number 42.86 into Go struct field StatusCakeMonitorMonitor.Uptime of type int
2018/10/09 16:15:45 Monitor Added: 3534601
2018/10/09 16:15:57 Monitor Name: jnf-app2
2018/10/09 16:15:57 Monitor URL: https://test-jnf-app2.testdomain.com/app_status
2018/10/09 16:15:58 Monitor already exists for ingress: jnf-app2
2018/10/09 16:15:59 Monitor couldn't be updated: jnf-app2
2018/10/09 16:15:59 No data has been updated (is any data different?)

Add statuscake support

StatusCake is another widely used downtime checker/notifier and we should include its support in IMC.

Add support for integrations in Pingdom

The check api definitions are here:

https://www.pingdom.com/api/2.1/#MethodCreate+New+Check

Basically, we need to be able to specify the integration ids for checks to allow checks created by the controller to have integration features.

integrationids | Integration identifiers. For example integrationids=11,22,33 | Comma separated Integers

The work is minimal, so I will see if I can submit a PR unless someone more familiar wants to do it.

[StatusCake Support] Stuck at Starting Ingress Monitor controller

Hi,

Good work for IngressMonitor,

I'm a StatusCake user, so I created an API key, and deployed configmap, rbac and Deployment of IngressMonitorController v1.0.6,

kind: ConfigMap
metadata:
  annotations:
    fabric8.io/target-platform: kubernetes
  labels:
    app: ingressmonitorcontroller
    version: 1.0.6
    group: com.stakater.platform
    provider: stakater
    chart: "IngressMonitorController-1.0.6"
    release: "RELEASE-NAME"
    heritage: "Tiller"
  name: ingressmonitorcontroller
data:
  config.yaml: |-
    providers:
    - name: UptimeRobot
      apiKey: <myKEY>
      apiURL: https://app.statuscake.com/API/
      alertContacts: Principal
    enableMonitorDeletion: true
    monitorNameTemplate: "{{.Namespace}}-{{.IngressName}}"

Small problem,

It start and stuck at Starting Ingress Monitor controller ...

So I think, I need to create an annotation for my ingresses now, and it doesn't change anything.

Thanks for debuging this with me.

(I work in IPv6 environment.)

Produces double-slashes in uptime URL

The IngressMonitorController seems to append an extra slash into the URL.

If the health endpoint of an pod is set to /myapp/health and the path of a corresponding ingress is set to '/', the final requested URL contains two slashes: https://example.com//myapp/health.

This breaks at least modern spring applications (they return http 500 with "The request was rejected because the URL was not normalized.").

A workaround is to specify the ingress without path: /.

Common check interval annotation

As suggested by The annotation monitor.stakater.com/pingdom/resolution can be abstracted into a general annotation such as monitor.stakater.com/resolutionTime as it can be used with premium services of uptimerobot and probably other services providers too.

Make it the annotation common and document that it is currently supported with pingdom only, we can later add support for resolution time for uptimerobot as well (Currently uptimerobot does not allow specifying resolution times manually for free services)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.