mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-11-09 10:19:16 +00:00
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
"use strict";(self.webpackChunkrancher_docs=self.webpackChunkrancher_docs||[]).push([[21830],{3905:(e,t,n)=>{n.d(t,{Zo:()=>p,kt:()=>d});var o=n(67294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,o,i=function(e,t){if(null==e)return{};var n,o,i={},a=Object.keys(e);for(o=0;o<a.length;o++)n=a[o],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)n=a[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var l=o.createContext({}),c=function(e){var t=o.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):r(r({},t),e)),n},p=function(e){var t=c(e.components);return o.createElement(l.Provider,{value:t},e.children)},m={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},u=o.forwardRef((function(e,t){var n=e.components,i=e.mdxType,a=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),u=c(n),d=i,g=u["".concat(l,".").concat(d)]||u[d]||m[d]||a;return n?o.createElement(g,r(r({ref:t},p),{},{components:n})):o.createElement(g,r({ref:t},p))}));function d(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var a=n.length,r=new Array(a);r[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s.mdxType="string"==typeof e?e:i,r[1]=s;for(var c=2;c<a;c++)r[c]=n[c];return o.createElement.apply(null,r)}return o.createElement.apply(null,n)}u.displayName="MDXCreateElement"},54186:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>m,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var o=n(87462),i=(n(67294),n(3905));const a={title:"Selectors and Scrape Configs"},r=void 0,s={unversionedId:"integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations",id:"integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations",title:"Selectors and Scrape Configs",description:"The Monitoring app sets prometheus.prometheusSpec.ignoreNamespaceSelectors=false, which enables monitoring across all namespaces by default.",source:"@site/docs/integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations.md",sourceDirName:"integrations-in-rancher/istio/configuration-options",slug:"/integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations",permalink:"/integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations",draft:!1,editUrl:"https://github.com/rancher/rancher-docs/edit/main/docs/integrations-in-rancher/istio/configuration-options/selectors-and-scrape-configurations.md",tags:[],version:"current",lastUpdatedAt:1666730461,formattedLastUpdatedAt:"Oct 25, 2022",frontMatter:{title:"Selectors and Scrape Configs"},sidebar:"tutorialSidebar",previous:{title:"Enable Istio with Pod Security Policies",permalink:"/integrations-in-rancher/istio/configuration-options/pod-security-policies"},next:{title:"Additional Steps for Installing Istio on an RKE2 Cluster",permalink:"/integrations-in-rancher/istio/configuration-options/install-istio-on-rke2-cluster"}},l={},c=[{value:"Limiting Monitoring to Specific Namespaces by Setting ignoreNamespaceSelectors to True",id:"limiting-monitoring-to-specific-namespaces-by-setting-ignorenamespaceselectors-to-true",level:3},{value:"Enabling Prometheus to Detect Resources in Other Namespaces",id:"enabling-prometheus-to-detect-resources-in-other-namespaces",level:3},{value:"Monitoring Specific Namespaces: Create a Service Monitor or Pod Monitor",id:"monitoring-specific-namespaces-create-a-service-monitor-or-pod-monitor",level:3},{value:"Monitoring across namespaces: Set ignoreNamespaceSelectors to False",id:"monitoring-across-namespaces-set-ignorenamespaceselectors-to-false",level:3}],p={toc:c};function m(e){let{components:t,...n}=e;return(0,i.kt)("wrapper",(0,o.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"The Monitoring app sets ",(0,i.kt)("inlineCode",{parentName:"p"},"prometheus.prometheusSpec.ignoreNamespaceSelectors=false"),", which enables monitoring across all namespaces by default."),(0,i.kt)("p",null,"This ensures you can view traffic, metrics and graphs for resources deployed in a namespace with ",(0,i.kt)("inlineCode",{parentName:"p"},"istio-injection=enabled")," label."),(0,i.kt)("p",null,"If you would like to limit Prometheus to specific namespaces, set ",(0,i.kt)("inlineCode",{parentName:"p"},"prometheus.prometheusSpec.ignoreNamespaceSelectors=true"),". Once you do this, you will need to add additional configuration to continue to monitor your resources."),(0,i.kt)("h3",{id:"limiting-monitoring-to-specific-namespaces-by-setting-ignorenamespaceselectors-to-true"},"Limiting Monitoring to Specific Namespaces by Setting ignoreNamespaceSelectors to True"),(0,i.kt)("p",null,"To limit monitoring to specific namespaces, you will edit the ",(0,i.kt)("inlineCode",{parentName:"p"},"ignoreNamespaceSelectors")," Helm chart option. You will configure this option when installing or upgrading the Monitoring Helm chart:"),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"When installing or upgrading the Monitoring Helm chart, edit the values.yml and set",(0,i.kt)("inlineCode",{parentName:"li"},"prometheus.prometheusSpec.ignoreNamespaceSelectors=true"),"."),(0,i.kt)("li",{parentName:"ol"},"Complete the install or upgrade.")),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Result:")," Prometheus will be limited to specific namespaces which means one of the following configurations will need to be set up to continue to view data in various dashboards"),(0,i.kt)("h3",{id:"enabling-prometheus-to-detect-resources-in-other-namespaces"},"Enabling Prometheus to Detect Resources in Other Namespaces"),(0,i.kt)("p",null,"There are two different ways to enable Prometheus to detect resources in other namespaces when ",(0,i.kt)("inlineCode",{parentName:"p"},"prometheus.prometheusSpec.ignoreNamespaceSelectors=true"),":"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("strong",{parentName:"li"},"Monitoring specific namespaces:")," Add a Service Monitor or Pod Monitor in the namespace with the targets you want to scrape."),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("strong",{parentName:"li"},"Monitoring across namespaces:")," Add an ",(0,i.kt)("inlineCode",{parentName:"li"},"additionalScrapeConfig")," to your rancher-monitoring instance to scrape all targets in all namespaces.")),(0,i.kt)("h3",{id:"monitoring-specific-namespaces-create-a-service-monitor-or-pod-monitor"},"Monitoring Specific Namespaces: Create a Service Monitor or Pod Monitor"),(0,i.kt)("p",null,"This option allows you to define which specific services or pods you would like monitored in a specific namespace."),(0,i.kt)("p",null,"The usability tradeoff is that you have to create the service monitor or pod monitor per namespace since you cannot monitor across namespaces."),(0,i.kt)("admonition",{title:"Prerequisite:",type:"note"},(0,i.kt)("p",{parentName:"admonition"},"Define a ServiceMonitor or PodMonitor for ",(0,i.kt)("inlineCode",{parentName:"p"},"<your namespace>"),". An example ServiceMonitor is provided below.")),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"Click ",(0,i.kt)("strong",{parentName:"li"},"\u2630 > Cluster Management"),"."),(0,i.kt)("li",{parentName:"ol"},"Go to the cluster that you created and click ",(0,i.kt)("strong",{parentName:"li"},"Explore"),"."),(0,i.kt)("li",{parentName:"ol"},"In the top navigation bar, open the kubectl shell."),(0,i.kt)("li",{parentName:"ol"},"If the ServiceMonitor or PodMonitor file is stored locally in your cluster, in ",(0,i.kt)("inlineCode",{parentName:"li"},"kubectl create -f <name of service/pod monitor file>.yaml"),"."),(0,i.kt)("li",{parentName:"ol"},"If the ServiceMonitor or PodMonitor is not stored locally, run ",(0,i.kt)("inlineCode",{parentName:"li"},"cat<< EOF | kubectl apply -f -"),", paste the file contents into the terminal, then run ",(0,i.kt)("inlineCode",{parentName:"li"},"EOF")," to complete the command."),(0,i.kt)("li",{parentName:"ol"},"Run ",(0,i.kt)("inlineCode",{parentName:"li"},"kubectl label namespace <your namespace> istio-injection=enabled")," to enable the envoy sidecar injection.")),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Result:")," ",(0,i.kt)("inlineCode",{parentName:"p"},"<your namespace>")," can be scraped by prometheus."),(0,i.kt)("figcaption",null,"Example Service Monitor for Istio Proxies"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"apiVersion: monitoring.coreos.com/v1\nkind: ServiceMonitor\nmetadata:\n name: envoy-stats-monitor\n namespace: istio-system\n labels:\n monitoring: istio-proxies\nspec:\n selector:\n matchExpressions:\n - {key: istio-prometheus-ignore, operator: DoesNotExist}\n namespaceSelector:\n any: true\n jobLabel: envoy-stats\n endpoints:\n - path: /stats/prometheus\n targetPort: 15090\n interval: 15s\n relabelings:\n - sourceLabels: [__meta_kubernetes_pod_container_port_name]\n action: keep\n regex: '.*-envoy-prom'\n - action: labeldrop\n regex: \"__meta_kubernetes_pod_label_(.+)\"\n - sourceLabels: [__meta_kubernetes_namespace]\n action: replace\n targetLabel: namespace\n - sourceLabels: [__meta_kubernetes_pod_name]\n action: replace\n targetLabel: pod_name\n")),(0,i.kt)("h3",{id:"monitoring-across-namespaces-set-ignorenamespaceselectors-to-false"},"Monitoring across namespaces: Set ignoreNamespaceSelectors to False"),(0,i.kt)("p",null,"This enables monitoring across namespaces by giving Prometheus additional scrape configurations."),(0,i.kt)("p",null,"The usability tradeoff is that all of Prometheus' ",(0,i.kt)("inlineCode",{parentName:"p"},"additionalScrapeConfigs")," are maintained in a single Secret. This could make upgrading difficult if monitoring is already deployed with additionalScrapeConfigs before installing Istio."),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"When installing or upgrading the Monitoring Helm chart, edit the values.yml and set the ",(0,i.kt)("inlineCode",{parentName:"li"},"prometheus.prometheusSpec.additionalScrapeConfigs")," array to the ",(0,i.kt)("strong",{parentName:"li"},"Additional Scrape Config")," provided below."),(0,i.kt)("li",{parentName:"ol"},"Complete the install or upgrade.")),(0,i.kt)("p",null,(0,i.kt)("strong",{parentName:"p"},"Result:")," All namespaces with the ",(0,i.kt)("inlineCode",{parentName:"p"},"istio-injection=enabled")," label will be scraped by prometheus."),(0,i.kt)("figcaption",null,"Additional Scrape Config"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-yaml"},"- job_name: 'istio/envoy-stats'\n scrape_interval: 15s\n metrics_path: /stats/prometheus\n kubernetes_sd_configs:\n - role: pod\n relabel_configs:\n - source_labels: [__meta_kubernetes_pod_container_port_name]\n action: keep\n regex: '.*-envoy-prom'\n - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]\n action: replace\n regex: ([^:]+)(?::\\d+)?;(\\d+)\n replacement: $1:15090\n target_label: __address__\n - action: labelmap\n regex: __meta_kubernetes_pod_label_(.+)\n - source_labels: [__meta_kubernetes_namespace]\n action: replace\n target_label: namespace\n - source_labels: [__meta_kubernetes_pod_name]\n action: replace\n target_label: pod_name\n")))}m.isMDXComponent=!0}}]); |