SlideShare a Scribd company logo
1
Securing and monitoring your K8s cluster
(RBAC + Prometheus)
2
What’s new in 1.6?
3
What’s new in 1.6? – Alpha features
•Per pod eviction
•Pod Injection Policy
•Custom Metrics support in the
Horizontal Pod Autoscaler
4
RBAC in Kubernetes 1.6
RBAC – Role Based Access Control
• Allows fine-grained authorization configuration
• Configurable via API
• Permissions are purely additive, there are no deny
permissions
• Uses concepts of Role and Role Bindings to create assign
and enforce permissions
• Permissions can be scoped to:
• Namespaces
• Nodes
• Control plane
• Enabled by starting the API server with the flag
• --authorization-mode=RBAC
5
RBAC - Attributes
A request has the following attributes that can be considered for
authorization:
• user (the user-string which a user was authenticated as).
• group (the list of group names the authenticated user is a
member of).
• “extra” (a map of arbitrary string keys to string values,
provided by the authentication layer)
• whether the request is for an API resource.
• the request path.
• allows authorizing access to miscellaneous non-resource
endpoints like /api or /healthz (see kubectl).
6
RBAC - Attributes
• The request verb.
• API
verbs get, list, create, update, patch, watch, proxy, redirect,
delete, and deletecollection are used for resource
requests
• HTTP verbs get, post, put, and delete are used for non-
resource requests
• What resource is being accessed (for resource requests only)
• What subresource is being accessed (for resource requests
only)
• The namespace of the object being accessed (for namespaced
resource requests only)
• The API group being accessed (for resource requests only); an
empty string designates the core API Group
7
RBAC – API Overview
Declares 4 top level types that can be interacted with via the API
or kubectl
• Role
• Cluster Role
• RoleBinding
• ClusterRoleBinding
8
RBAC – Role
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
9
RBAC – RoleBinding to Role
# This role binding allows "jane" to read pods in
the "default" namespace.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
10
RBAC – ClusterRole
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
# "namespace" omitted since ClusterRoles are
not namespaced
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
11
RBAC – RoleBinding to ClusterRole
# This role binding allows "dave" to read secrets in
the "development" namespace.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-secrets
namespace: development # This only grants
permissions within the "development" namespace.
subjects:
- kind: User
name: dave
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
12
RBAC – ClusterRoleBinding
# This cluster role binding allows anyone in the
"manager" group to read secrets in any namespace.
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: manager
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
13
RBAC – Use Cases
• Limit user access to specific namespaces
• Limit user permissions relative to their Role
• Group users based on their Roles and assign permissions to the
group
• Pre-assign special hardware nodes to certain user groups and
workloads
• Segment your continuous deployment pipeline with
permissions to deploy in to only specific namespaces.
14
Hierarchy of reliability - Monitoring
15
Prometheus
What is Prometheus?
• Monitoring system and time series database
• Inspired by BorgMon
• Not BorgMon
• Opensource – developed at SoundCloud initially
• How does it work?
• Collects metrics at scale via HTTP
• Easy scaling
• Can handle thousands of targets, millions of timeseries
16
Prometheus - Features
• Multi-dimensional data model
• Flexible query language to leverage dimensionality
• No reliance on distributed storage, autonomous single server
nodes
• Collection happens via a pull model over HTTP
• Push is also supported via an intermediary gateway
• Targets can be discovered statically or via service discovery
• Good graphing and dashboarding support
17
Prometheus Architecture
18
Running Prometheus in Kubernetes
• What we need
• Pod specification defining how to run Prometheus
• Load and manage configuration
• Service specification to access Prometheus on stable IP
• Options
• Write own pod+service+petset+... manifests
• Kubernetes Helm chart in the making
https://github.com/kubernetes/charts/pull/151
• CoreOS wrote an Operator managing Prometheus and its
configuration
https://github.com/coreos/kube-prometheus
19
Prometheus Operator by CoreOS
• What is an Operator?
• Builds on basic Kubernetes resource and controller
concepts
• Included application domain knowledge and best practices
• Frees you from deployment and lifecycle management
details
• Prometheus Operator by CoreOS
• Single command install
• Configure manage instances using a single declarative
configuration
• Configuration drives the creation, configuration and
management of Prometheus instances
20
Prometheus Operator - Features
• Create/Destroy
• Simple Configuration
• Target Services via Labels
21
Prometheus Operator – How does it work?
The Operator defines 2 Third Party Resources(TPR)
• Prometheus Resource
• Data Retention
• Persistent Volume Claims
• Number of replicas
• Version
• Alert Managers
• Service Monitor
22
Prometheus Operator – How does it work?
23
Prometheus Operator - Deployment
Deploy the operator
$ kubectl create -f
https://coreos.com/operators/prometheus/latest/prometheus
-operator.yaml
deployment "prometheus-operator" created
Create the Prometheus TPR
apiVersion: monitoring.coreos.com/v1alpha1
kind: Prometheus
metadata:
name: prometheus-k8s
labels: prometheus: k8s
spec: version: v1.3.0
$ kubectl create -f
https://coreos.com/operators/prometheus/latest/prometheus
-k8s.yaml
24
Prometheus Operator – Cluster Monitoring
Deploy exporters providing metrics on cluster nodes and
Kubernetes business logic
$ kubectl create -f
https://coreos.com/operators/prometheus/latest/exporters.
yaml deployment
"kube-state-metrics"
created service "kube-state-metrics"
created daemonset "node-exporter"
created service "node-exporter" created
Create the ConfigMap containing the Prometheus
configuration
$ kubectl apply -f
https://coreos.com/operators/prometheus/latest/prometheus
-k8s-cm.yaml
configmap "prometheus-k8s" configured
25
Prometheus Operator – Cluster Monitoring
26
Prometheus Operator – Service Monitoring
Define how a service should be monitored
apiVersion: monitoring.coreos.com/v1alpha1
kind: ServiceMonitor
metadata:
name: frontend
labels:
tier: frontend
spec:
selector:
matchLabels:
tier: frontend
endpoints:
- port: web # works for different port numbers as long as
the name matches
interval: 10s # scrape the endpoint every 10 seconds
27
Prometheus Operator – Service Monitoring
Create a Prometheus instance that includes this
ServiceMonitor
apiVersion: monitoring.coreos.com/v1alpha1
kind: Prometheus
metadata:
name: prometheus-frontend
labels: prometheus: frontend
spec: version: v1.3.0 # Define that all ServiceMonitor
TPRs with the label `tier = frontend` should be included
# into the server's configuration.
serviceMonitors:
- selector:
matchLabels: tier: frontend
28
Create the Service monitor and Prometheus Objects
$ kubectl create -f
https://coreos.com/operators/prometheus/latest/servicemon
itor-frontend.yaml
servicemonitor "frontend" created
$ kubectl create -f
https://coreos.com/operators/prometheus/latest/prometheus
-frontend.yaml
prometheus "prometheus-frontend"
created service "prometheus-frontend" created
Prometheus Operator – Service Monitoring
29
Prometheus Operator – Service Monitoring
Deploy an application that matches the label tier =
frontend
$ kubectl create –f ./example-app.yaml
30
Thank You

More Related Content

PDF
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Etsuji Nakai
 
PDF
Kubernetes 101
Crevise Technologies
 
PDF
Kubernetes 101 for Developers
Ross Kukulinski
 
PPTX
DevOps with Kubernetes
EastBanc Tachnologies
 
PPTX
K8S in prod
Mageshwaran Rajendran
 
PPTX
Container Orchestration
dfilppi
 
PPTX
Kubernetes Introduction
Martin Danielsson
 
PDF
Building stateful applications on Kubernetes with Rook
Roberto Hashioka
 
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Etsuji Nakai
 
Kubernetes 101
Crevise Technologies
 
Kubernetes 101 for Developers
Ross Kukulinski
 
DevOps with Kubernetes
EastBanc Tachnologies
 
Container Orchestration
dfilppi
 
Kubernetes Introduction
Martin Danielsson
 
Building stateful applications on Kubernetes with Rook
Roberto Hashioka
 

What's hot (20)

PDF
The Operator Pattern - Managing Stateful Services in Kubernetes
QAware GmbH
 
PPTX
OpenStack High Availability
Jakub Pavlik
 
PDF
Kubernetes Node Deep Dive
Lei (Harry) Zhang
 
PPTX
How to Develop OpenStack
Mehdi Ali Soltani
 
PDF
Comparison of control plane deployment architectures in the scope of hypercon...
Miroslav Halas
 
PDF
Kubernetes - A Comprehensive Overview
Bob Killen
 
PPTX
Tối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G core
Vietnam Open Infrastructure User Group
 
PDF
Fully automated kubernetes deployment and management
LinuxCon ContainerCon CloudOpen China
 
PPTX
Docker and kubernetes
Dongwon Kim
 
PDF
K8s storage-glusterfs-20180210
Che-Chia Chang
 
PDF
Status of Embedded Linux
LinuxCon ContainerCon CloudOpen China
 
PPTX
KuberNETes - meetup
Nathan Ness
 
PDF
Is there still room for innovation in container orchestration and scheduling
LinuxCon ContainerCon CloudOpen China
 
PDF
Dockerizing OpenStack for High Availability
Daniel Krook
 
PPTX
Serverless technologies with Kubernetes
Provectus
 
PDF
Cloudfoundry Overview
rajdeep
 
PPTX
Topologies of OpenStack
haribabu kasturi
 
PDF
Testing kubernetes and_open_shift_at_scale_20170209
mffiedler
 
PDF
Scale Kubernetes to support 50000 services
LinuxCon ContainerCon CloudOpen China
 
PPTX
Kata Container - The Security of VM and The Speed of Container | Yuntong Jin
Vietnam Open Infrastructure User Group
 
The Operator Pattern - Managing Stateful Services in Kubernetes
QAware GmbH
 
OpenStack High Availability
Jakub Pavlik
 
Kubernetes Node Deep Dive
Lei (Harry) Zhang
 
How to Develop OpenStack
Mehdi Ali Soltani
 
Comparison of control plane deployment architectures in the scope of hypercon...
Miroslav Halas
 
Kubernetes - A Comprehensive Overview
Bob Killen
 
Tối ưu hiệu năng đáp ứng các yêu cầu của hệ thống 4G core
Vietnam Open Infrastructure User Group
 
Fully automated kubernetes deployment and management
LinuxCon ContainerCon CloudOpen China
 
Docker and kubernetes
Dongwon Kim
 
K8s storage-glusterfs-20180210
Che-Chia Chang
 
Status of Embedded Linux
LinuxCon ContainerCon CloudOpen China
 
KuberNETes - meetup
Nathan Ness
 
Is there still room for innovation in container orchestration and scheduling
LinuxCon ContainerCon CloudOpen China
 
Dockerizing OpenStack for High Availability
Daniel Krook
 
Serverless technologies with Kubernetes
Provectus
 
Cloudfoundry Overview
rajdeep
 
Topologies of OpenStack
haribabu kasturi
 
Testing kubernetes and_open_shift_at_scale_20170209
mffiedler
 
Scale Kubernetes to support 50000 services
LinuxCon ContainerCon CloudOpen China
 
Kata Container - The Security of VM and The Speed of Container | Yuntong Jin
Vietnam Open Infrastructure User Group
 
Ad

Similar to Securing & Monitoring Your K8s Cluster with RBAC and Prometheus”. (20)

PPTX
Kubernetes security with AWS
Kasun Madura Rathnayaka
 
PDF
Securing Prometheus. Lessons Learned from OpenShift.pdf
Jesús Ángel Samitier
 
PDF
Monitoring on Kubernetes using Prometheus - Chandresh
CodeOps Technologies LLP
 
PPTX
Monitoring on Kubernetes using prometheus
Chandresh Pancholi
 
PDF
Kubernetes extensibility: crd & operators
Giacomo Tirabassi
 
PDF
Kubernetes extensibility: CRDs & Operators
SIGHUP
 
PDF
Download full Managing Kubernetes operating Kubernetes clusters in the real w...
duduhasikul
 
PDF
Prometheus monitoring
Hien Nguyen Van
 
PDF
The hitchhiker’s guide to Prometheus
Bol.com Techlab
 
PDF
The hitchhiker’s guide to Prometheus
Bol.com Techlab
 
PPTX
Kubernetes basics information along with stateful session info
Kapildev292285
 
PDF
Monitoring a Kubernetes-backed microservice architecture with Prometheus
Fabian Reinartz
 
PPTX
How kubernetes operators can rescue dev secops in midst of a pandemic updated
Shikha Srivastava
 
PPTX
Introduction to kubernetes
Rishabh Indoria
 
PPTX
Database as a Service (DBaaS) on Kubernetes
ObjectRocket
 
PPTX
K8s security best practices
Sharon Vendrov
 
PPTX
Monitoring kubernetes with prometheus-operator
Lili Cosic
 
PDF
Kubernetes Security Best Practices for DevOps
DevOps.com
 
PDF
Kubernetes From Scratch .pdf
ssuser9b44c7
 
PDF
KubeCon EU 2016 Keynote: Pushing Kubernetes Forward
KubeAcademy
 
Kubernetes security with AWS
Kasun Madura Rathnayaka
 
Securing Prometheus. Lessons Learned from OpenShift.pdf
Jesús Ángel Samitier
 
Monitoring on Kubernetes using Prometheus - Chandresh
CodeOps Technologies LLP
 
Monitoring on Kubernetes using prometheus
Chandresh Pancholi
 
Kubernetes extensibility: crd & operators
Giacomo Tirabassi
 
Kubernetes extensibility: CRDs & Operators
SIGHUP
 
Download full Managing Kubernetes operating Kubernetes clusters in the real w...
duduhasikul
 
Prometheus monitoring
Hien Nguyen Van
 
The hitchhiker’s guide to Prometheus
Bol.com Techlab
 
The hitchhiker’s guide to Prometheus
Bol.com Techlab
 
Kubernetes basics information along with stateful session info
Kapildev292285
 
Monitoring a Kubernetes-backed microservice architecture with Prometheus
Fabian Reinartz
 
How kubernetes operators can rescue dev secops in midst of a pandemic updated
Shikha Srivastava
 
Introduction to kubernetes
Rishabh Indoria
 
Database as a Service (DBaaS) on Kubernetes
ObjectRocket
 
K8s security best practices
Sharon Vendrov
 
Monitoring kubernetes with prometheus-operator
Lili Cosic
 
Kubernetes Security Best Practices for DevOps
DevOps.com
 
Kubernetes From Scratch .pdf
ssuser9b44c7
 
KubeCon EU 2016 Keynote: Pushing Kubernetes Forward
KubeAcademy
 
Ad

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Software Development Methodologies in 2025
KodekX
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 

Securing & Monitoring Your K8s Cluster with RBAC and Prometheus”.

  • 1. 1 Securing and monitoring your K8s cluster (RBAC + Prometheus)
  • 3. 3 What’s new in 1.6? – Alpha features •Per pod eviction •Pod Injection Policy •Custom Metrics support in the Horizontal Pod Autoscaler
  • 4. 4 RBAC in Kubernetes 1.6 RBAC – Role Based Access Control • Allows fine-grained authorization configuration • Configurable via API • Permissions are purely additive, there are no deny permissions • Uses concepts of Role and Role Bindings to create assign and enforce permissions • Permissions can be scoped to: • Namespaces • Nodes • Control plane • Enabled by starting the API server with the flag • --authorization-mode=RBAC
  • 5. 5 RBAC - Attributes A request has the following attributes that can be considered for authorization: • user (the user-string which a user was authenticated as). • group (the list of group names the authenticated user is a member of). • “extra” (a map of arbitrary string keys to string values, provided by the authentication layer) • whether the request is for an API resource. • the request path. • allows authorizing access to miscellaneous non-resource endpoints like /api or /healthz (see kubectl).
  • 6. 6 RBAC - Attributes • The request verb. • API verbs get, list, create, update, patch, watch, proxy, redirect, delete, and deletecollection are used for resource requests • HTTP verbs get, post, put, and delete are used for non- resource requests • What resource is being accessed (for resource requests only) • What subresource is being accessed (for resource requests only) • The namespace of the object being accessed (for namespaced resource requests only) • The API group being accessed (for resource requests only); an empty string designates the core API Group
  • 7. 7 RBAC – API Overview Declares 4 top level types that can be interacted with via the API or kubectl • Role • Cluster Role • RoleBinding • ClusterRoleBinding
  • 8. 8 RBAC – Role kind: Role apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: namespace: default name: pod-reader rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods"] verbs: ["get", "watch", "list"]
  • 9. 9 RBAC – RoleBinding to Role # This role binding allows "jane" to read pods in the "default" namespace. kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: read-pods namespace: default subjects: - kind: User name: jane apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.io
  • 10. 10 RBAC – ClusterRole kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: # "namespace" omitted since ClusterRoles are not namespaced name: secret-reader rules: - apiGroups: [""] resources: ["secrets"] verbs: ["get", "watch", "list"]
  • 11. 11 RBAC – RoleBinding to ClusterRole # This role binding allows "dave" to read secrets in the "development" namespace. kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: read-secrets namespace: development # This only grants permissions within the "development" namespace. subjects: - kind: User name: dave apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.io
  • 12. 12 RBAC – ClusterRoleBinding # This cluster role binding allows anyone in the "manager" group to read secrets in any namespace. kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: read-secrets-global subjects: - kind: Group name: manager apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.io
  • 13. 13 RBAC – Use Cases • Limit user access to specific namespaces • Limit user permissions relative to their Role • Group users based on their Roles and assign permissions to the group • Pre-assign special hardware nodes to certain user groups and workloads • Segment your continuous deployment pipeline with permissions to deploy in to only specific namespaces.
  • 15. 15 Prometheus What is Prometheus? • Monitoring system and time series database • Inspired by BorgMon • Not BorgMon • Opensource – developed at SoundCloud initially • How does it work? • Collects metrics at scale via HTTP • Easy scaling • Can handle thousands of targets, millions of timeseries
  • 16. 16 Prometheus - Features • Multi-dimensional data model • Flexible query language to leverage dimensionality • No reliance on distributed storage, autonomous single server nodes • Collection happens via a pull model over HTTP • Push is also supported via an intermediary gateway • Targets can be discovered statically or via service discovery • Good graphing and dashboarding support
  • 18. 18 Running Prometheus in Kubernetes • What we need • Pod specification defining how to run Prometheus • Load and manage configuration • Service specification to access Prometheus on stable IP • Options • Write own pod+service+petset+... manifests • Kubernetes Helm chart in the making https://github.com/kubernetes/charts/pull/151 • CoreOS wrote an Operator managing Prometheus and its configuration https://github.com/coreos/kube-prometheus
  • 19. 19 Prometheus Operator by CoreOS • What is an Operator? • Builds on basic Kubernetes resource and controller concepts • Included application domain knowledge and best practices • Frees you from deployment and lifecycle management details • Prometheus Operator by CoreOS • Single command install • Configure manage instances using a single declarative configuration • Configuration drives the creation, configuration and management of Prometheus instances
  • 20. 20 Prometheus Operator - Features • Create/Destroy • Simple Configuration • Target Services via Labels
  • 21. 21 Prometheus Operator – How does it work? The Operator defines 2 Third Party Resources(TPR) • Prometheus Resource • Data Retention • Persistent Volume Claims • Number of replicas • Version • Alert Managers • Service Monitor
  • 22. 22 Prometheus Operator – How does it work?
  • 23. 23 Prometheus Operator - Deployment Deploy the operator $ kubectl create -f https://coreos.com/operators/prometheus/latest/prometheus -operator.yaml deployment "prometheus-operator" created Create the Prometheus TPR apiVersion: monitoring.coreos.com/v1alpha1 kind: Prometheus metadata: name: prometheus-k8s labels: prometheus: k8s spec: version: v1.3.0 $ kubectl create -f https://coreos.com/operators/prometheus/latest/prometheus -k8s.yaml
  • 24. 24 Prometheus Operator – Cluster Monitoring Deploy exporters providing metrics on cluster nodes and Kubernetes business logic $ kubectl create -f https://coreos.com/operators/prometheus/latest/exporters. yaml deployment "kube-state-metrics" created service "kube-state-metrics" created daemonset "node-exporter" created service "node-exporter" created Create the ConfigMap containing the Prometheus configuration $ kubectl apply -f https://coreos.com/operators/prometheus/latest/prometheus -k8s-cm.yaml configmap "prometheus-k8s" configured
  • 25. 25 Prometheus Operator – Cluster Monitoring
  • 26. 26 Prometheus Operator – Service Monitoring Define how a service should be monitored apiVersion: monitoring.coreos.com/v1alpha1 kind: ServiceMonitor metadata: name: frontend labels: tier: frontend spec: selector: matchLabels: tier: frontend endpoints: - port: web # works for different port numbers as long as the name matches interval: 10s # scrape the endpoint every 10 seconds
  • 27. 27 Prometheus Operator – Service Monitoring Create a Prometheus instance that includes this ServiceMonitor apiVersion: monitoring.coreos.com/v1alpha1 kind: Prometheus metadata: name: prometheus-frontend labels: prometheus: frontend spec: version: v1.3.0 # Define that all ServiceMonitor TPRs with the label `tier = frontend` should be included # into the server's configuration. serviceMonitors: - selector: matchLabels: tier: frontend
  • 28. 28 Create the Service monitor and Prometheus Objects $ kubectl create -f https://coreos.com/operators/prometheus/latest/servicemon itor-frontend.yaml servicemonitor "frontend" created $ kubectl create -f https://coreos.com/operators/prometheus/latest/prometheus -frontend.yaml prometheus "prometheus-frontend" created service "prometheus-frontend" created Prometheus Operator – Service Monitoring
  • 29. 29 Prometheus Operator – Service Monitoring Deploy an application that matches the label tier = frontend $ kubectl create –f ./example-app.yaml