github.com/google/cloudprober@v0.11.3/docs/content/concepts/targets.md (about)

     1  ---
     2  menu:
     3      main:
     4          name: "Targets Discovery"
     5          weight: 2
     6  title: "Targets Discovery"
     7  date: 2019-10-25T17:24:32-07:00
     8  ---
     9  Automatic and continuous discovery of the targets is one of the core features of
    10  Cloudprober. This feature is specially critical for the dynamic environments that today's cloud based deployments make possible. For exmaple, in a kubernetes cluster number of pods and their IPs can change on the fly, either in response to replica count changes or node failures. Automated targets discovery makes sure that we don't have to reconfigure Cloudprober in response to such events.
    11  
    12  ## Overview
    13  The main idea behind Cloudprober's targets discovery is to use an independent source of truth to figure out the targets we are supposed to monitor. This source of truth is usually the resource provider's API, for example, GCE API and Kubernetes API. Cloudprober periodically polls these APIs to get the latest list of resources.
    14  
    15  Example targets configuration:
    16  
    17  ```bash
    18  targets {
    19    rds_targets {
    20      # Monitor all endpoints for the service service-a
    21      resource_path: "k8s://endpoints/service-a"
    22    }
    23  }
    24  ```
    25  
    26  
    27  
    28  Some salient features of the cloudprober's targets discovery:
    29  
    30  * Continuous discovery. We don't just discover targets in the beginning, but keep refreshing them at a regular interval.
    31  * Protection against the upstream provider failures. If refreshing of the targets fails during one of the refresh cycles, we continue using the existing set of targets.
    32  * Targets data includes name, labels, IP and ports (labels and ports are optional). These details allow configuring probes, for example, automatically setting port in the HTTP probe, and using target lables for probe results labeling.
    33  * Well-defined protobuf based API (RDS -- more on it below) to add support for more target types.
    34  * Currently supports GCE and Kubernetes resources. Adding more resource types should be straightforward. 
    35  
    36  Cloudprober currently (__as of v0.10.7__) supports following types of dynamic targets:
    37  
    38  Resource Provider       | Resource Types 
    39  -------------------------------|---------
    40  Kubernetes (k8s)         | pods, endpoints, services      
    41  GCP (gcp)                      | gce_instances, pubsub_messages 
    42  
    43  
    44  ## Resource Discovery Service
    45  
    46  To provide a consistent interface between targets' configuration and the actual implementation, Cloudprober defines and uses a protocol called RDS (Resource Discovery Service). Cloudprober's targets module includes a targets type "rds_targets", that talks to an RDS backend that is either part of the same process or available over gRPC.
    47  
    48  
    49  <a href="/diagrams/rds_targets.png"><img style="float: center;" width=450px src="/diagrams/rds_targets.png"></a>
    50  
    51  Here are the RDS targets configuration ([RDSTargets](https://github.com/google/cloudprober/blob/86a1d1fcd2f8505c45ff462d69458fd5b9964e5f/targets/proto/targets.proto#L12)) options:
    52  
    53  ```protobuf
    54  message RDSTargets {
    55    // RDS server options, for example:
    56    // rds_server_options {
    57    //   server_address: "rds-server.xyz:9314"
    58    //   oauth_config: {
    59    //     ...
    60    //   }
    61    // }
    62    // Default is to use the local server if any.
    63    optional rds.ClientConf.ServerOptions rds_server_options = 1;
    64  
    65    // Resource path specifies the resources to return. Resources paths have the
    66    // following format:
    67    // <resource_provider>://<resource_type>/<additional_params>
    68    //
    69    // Examples:
    70    // For GCE instances in projectA: "gcp://gce_instances/<projectA>"
    71    // Kubernetes Pods : "k8s://pods"
    72    optional string resource_path = 2;
    73  
    74    // Filters to filter resources by. Example:
    75    // filter {
    76    //   key: "namespace"
    77    //   value: "mynamesspace"
    78    // }
    79    // filter {
    80    //   key: "labels.app"
    81    //   value: "web-service"
    82    // }
    83    repeated rds.Filter filter = 3;
    84  
    85    // IP config to specify the IP address to pick for a resource. IPConfig
    86    // is defined here:
    87    // https://github.com/google/cloudprober/blob/master/rds/proto/rds.proto
    88    optional rds.IPConfig ip_config = 4;
    89  }
    90  ```
    91  
    92  Most options are explained in the comments for quick references. Here is the further explanation of some of these options:
    93  
    94  ### rds_server_options
    95  This [field](https://github.com/google/cloudprober/blob/86a1d1fcd2f8505c45ff462d69458fd5b9964e5f/rds/client/proto/config.proto#L19) specifies how to connect to the RDS server: server address and security options (OAuth and TLS). If left unspecified, it connects to the local server if any (started through `rds_server` option). Next up it looks for the `rds_server_options` in [global_targets_options](https://github.com/google/cloudprober/blob/86a1d1fcd2f8505c45ff462d69458fd5b9964e5f/targets/proto/targets.proto#L125). 
    96  
    97  ### resource_path
    98  Resource path specifies the resources we are interested in. It consists of _resource provider_, _resource type_ and optional _relative path_: `<resource_provider>://<resource_type>/<optional_relative_path>`
    99    * `resource_provider`: Resource provider is a generic concept within the RDS protocol but usually maps to the cloud provider. Cloudprober RDS server currently implements the Kubernetes (k8s) and GCP (gcp) resource providers. We plan to add more resource providers in future.
   100    * `resource_type`: Available resource types depend on the providers, for example, for k8s provider supports the following resource types: _pods_, _endpoints_, and _services_.
   101    * `optional_relative_path`: For most resource types you can specify resource name in the resource path itself, e.g. `k8s://services/cloudprober`. Alternatively, you can use filters to filter by name, resource, etc.
   102  
   103  ### filter
   104  Filters are key-value strings that can be used to filter resources by various fields. Filters depend on the resource types, but most resources support filtering by name and labels.
   105  
   106  ```
   107  # Return resources that start with "web" and have label "service:service-a"
   108  ...
   109   filter {
   110     key: "name"
   111     value: "^web.*"
   112   }
   113   filter {
   114     key: "labels.service"
   115     value: "service-a"
   116   }
   117  ```
   118  
   119  * Filters supported by kubernetes resources: [k8s filters](https://github.com/google/cloudprober/blob/e4a0321d38d75fb4655d85632b52039fa7279d1b/rds/kubernetes/kubernetes.go#L55).
   120  * Filters supported by GCP:
   121    * [GCE Instances](https://github.com/google/cloudprober/blob/e4a0321d38d75fb4655d85632b52039fa7279d1b/rds/gcp/gce_instances.go#L44)
   122    * [Pub/Sub Messages](https://github.com/google/cloudprober/blob/e4a0321d38d75fb4655d85632b52039fa7279d1b/rds/gcp/pubsub.go#L34)
   123  
   124  ## Running RDS Server
   125  
   126  RDS server can either be run as an independent process or it can be part of the main prober process. Former mode is useful for large deployments where you may want to reduce the API upcall traffic (for example, to GCP). For example, if you run 1000+ prober processes, it will be much more economical, from the API quota usage point of view, to have a centralized RDS service with much fewer (2-3) instances instead of having each prober process make its own API calls.
   127  
   128  RDS server can be added to a cloudprober process using the `rds_server` stanza. If you're running RDS server in a remote process, you'll have to enable gRPC server in that process (using `grpc_port`) so that other instances can access it remotely.
   129  
   130  Here is an example RDS server configuration:
   131  
   132  ```shell
   133  rds_server {
   134    # GCP provider to discover GCP resources.
   135    provider {
   136      gcp_config {
   137        # Projects to discover resources in.
   138        project: "test-project-1"
   139        project: "test-project-2"
   140  
   141        # Discover GCE instances in us-central1.
   142        gce_instances {
   143          zone_filter: "name = us-central1-*"
   144          re_eval_sec: 60  # How often to refresh, default is 300s.
   145        }
   146  
   147        # GCE forwarding rules.
   148        forwarding_rules {}
   149      }
   150    }
   151  
   152    # Kubernetes targets are further discussed at:
   153    # https://cloudprober.org/how-to/run-on-kubernetes/#kubernetes-targets
   154    provider {
   155      kubernetes_config {
   156        endpoints {}
   157      }
   158    }
   159  }
   160  
   161  # Enable gRPC server for RDS. Only required for remote access to RDS server.
   162  grpc_port: 9314
   163  ```
   164  
   165  For the remote RDS server setup, if accessing over external network, you can secure the underlying gRPC communication using [TLS certificates](https://github.com/google/cloudprober/blob/master/config/proto/config.proto#L91).
   166