Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes healthcheck #100

Merged
merged 12 commits into from
Mar 20, 2019
Merged

Add Kubernetes healthcheck #100

merged 12 commits into from
Mar 20, 2019

Conversation

CarlosLanderas
Copy link
Contributor

New Kubernetes HealthCheck with initial support for Deployments, Pods and Services.
Good to monitor your Asp.Net application dependencies that are running within a k8s cluster.

This healthcheck is also good for configuring a HealthChecks UI interface to verify cluster status like nagios does.

All Checks can configure a condition against V1Deployment, V1Pod and V1Service so you can practically configure whatever condition with the k8s API returned object. (Spec, Metadata, Status, etc...)

Below there are some samples configuring conditions like desired replicas and ready replicas, checking the configured type for a service or confirming that a given pod has the target configured label.
But you could configure all kind of checks to meet your criteria.

Sample with configuration using .kubeconfig

  services
    .AddHealthChecks()
    .AddKubernetes(setup =>
     {
      setup.WithConfiguration(k8s.KubernetesClientConfiguration.BuildConfigFromConfigFile())
       .CheckDeployment("wordpress-one-wordpress",
                  d => d.Status.Replicas == 2 && d.Status.ReadyReplicas == 2)
       .CheckService("wordpress-one-wordpress", s => s.Spec.Type == "LoadBalancer")
       .CheckPod("myapp-pod", p => p.Metadata.Labels["app"] == "myapp");
     });

Sample configuring a remote AKS Cluster:

services
.AddHealthChecks()
.AddKubernetes(setup =>
    {
    setup.WithConfiguration(new KubernetesClientConfiguration
      {
        Host = "https://my-aks-cluster.westeurope.azmk8s.io:443",
        SkipTlsVerify = true,
        AccessToken = "youraccesstoken"
      })
     .CheckDeployment("wordpress-one-wordpress",
               d => d.Status.Replicas == 2 && d.Status.ReadyReplicas == 2)
     .CheckService("wordpress-one-wordpress", s => s.Spec.Type == "LoadBalancer")
     .CheckPod("myapp-pod", p => p.Metadata.Labels["app"] == "myapp");
});

@CarlosLanderas
Copy link
Contributor Author

@unaizorrilla did you have time to review this? I know.some people that.would use it as soon as published

@CarlosLanderas CarlosLanderas merged commit 40b5ae3 into master Mar 20, 2019
@CarlosLanderas CarlosLanderas deleted the kubernetes-healthcheck branch June 30, 2019 18:31
@sungam3r sungam3r mentioned this pull request Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant