SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Running a managed service on
Kubernetes and PostgreSQL
What we learned at Timescale
DoK Day Europe, May 16th, 2022
Oleksii Kliukin
TimescaleDB is
PostgreSQL, supercharged for
time-series data and analytics.
TimescaleDB is
free and open PostgreSQL
extension
Timescale Cloud is a hosted
and fully managed TimescaleDB
running on Kubernetes
Agenda
01
02
Architecture overview 🏗
Challenges 🙃
01
Architecture overview
Timescale cloud DB on Kubernetes / AWS
02
Challenges
And solutions
• Timescale continuous/real-time aggregates may require a lot of
memory. Out of memory (OOM) when limits are set low is not
uncommon.
• OOM behavior assumed by PostgreSQL developers:



• Linux OOM killer: SIGKILL a random Postgres process
• A backend process is killed: disruption, restart of every connection
• A postmaster is killed: unclean shutdown, in extreme cases to
startup instance
Challenges
OOM killer
OOM causes abrupt shutdown of PostgreSQL
ERROR: out of memory on a request of 1024 bytes
Challenges
OOM killer
OOM causes abrupt shutdown of PostgreSQL
$ kubectl get pod tinyforkv01-an-0 -o json
jq '.spec.containers[0].resources'
{
"limits": {
"cpu": "4",
"memory": "1Gi"
},
"requests": {
"cpu": "4",
"memory": "1Gi"
}
}
Challenges
OOM killer
OOM causes abrupt shutdown of PostgreSQL
* Image source: user MesserWoland, https://en.m.wikipedia.org/wiki/File:The_death.svg
*
• Regular PostgreSQL: set memory overcommit, enable swap
• vm.overcommit_memory = 2
• Can’t set it individually per container
• A node typically runs some pods (eg. daemonsets for logging)
incompatible with this setting



https://github.com/kubernetes/kubernetes/issues/90973
Challenges
OOM killer
OOM causes abrupt shutdown of PostgreSQL
• Solution: OOMGuard library collects statistics on the memory
usage, overriding malloc
• Use LD_PRELOAD_LIBRARY to install it for Postgres
processes
• Can just report statics, or actually block allocations going above
the predefined threshold, emulating regular malloc behavior
• OOM_GUARD_LIMIT threshold is derived from the container
memory limit, accounting for shared_buffers and OS overhead.
Challenges
OOM killer
OOM causes abrupt shutdown of PostgreSQL
• PostgreSQL: provide memory allocation hooks to do internal
accounting and deny allocations via extensions.
• Linux/Kubernetes: configure oom_adj_score and
vm_overcommit per cgroup on the Linux/Kubernetes layer.
• Improved debugging experience (locating debug symbols from
the container when running perf or gdb on the host)
Challenges
OOM killer
Wishlist
• New versions of Timescale extension are released regularly
• A new timescale-docker-ha image is built once the extension is
released
• We want to deliver latest extension (but not necessary auto-
upgrade) to our customers immediately
• Changing pod’s docker image requires a pod restart
• Planned customer downtime may only happen during
maintenance window, only a few times a year
Challenges
Fewer downtimes
Extension updates require a pod bounce
Challenges
Fewer downtimes
Extension updates require a pod bounce
• Solution: hot-forge
• A binary inside the container to fetch pre-packaged bundles and
put them in the container
• The bundles are delivered using a postgres connection (COPY
TO PROGRAM)
• The bundles are written to a persistent volume and linked to a
container filesystem
• Mostly adding new data (although can potentially replace/delete
existing files in the container)
Challenges
Fewer downtimes
Extension updates require a pod bounce
• Allow bouncing of individual containers in the pod and changing
the docker image
• Support “mutable” area inside the pod to deliver updates.
Challenges
Fewer downtimes
Wishlist
• Etcd is a core of the Kubernetes cluster
• Consists of multiple nodes (we run 5) - should be resilient?
• Can degrade on master node updates
• Performance issues (EBS burst balance, too many objects)
• Patroni dependency (no Kubernetes API - instances are read-
only)
Challenges
Operating Etcd
Etcd is a 5-nodes single point of failure
Image source: Andy Langager, https://www.flickr.com/photos/andylangager/8631388149
• Solution: no silver bullet
• Many small clusters in each region instead of a single big one
• Etcd performance monitoring
• Fire drills on ephemeral clusters
• Solution: Patroni experimental static_primary mode:
• Enforce single primary by rejecting connections from other
nodes
• Do not demote when Kubernetes API is not available
Challenges
Operating Etcd
Etcd is a 5-nodes single point of failure
• Some operational instructions when Etcd is down
• Better observability inside Etcd
• Patroni “isolated” mode scalable to any number of pods
Challenges
Operating Etcd
Wishlist
• New (1TB+) encrypted EBS volumes show an existing partition
marker (Atari partition)
• Kubernetes refuses to format them
• Pod is stuck at startup
Challenges
AWS bugs
Encrypted EBS volumes
Image source: Bill Bertram, https://commons.wikimedia.org/wiki/File:Atari_1040STf.jpg
• Solution: create a small 1GB encrypted volume
• Snapshot it into a “golden snapshot”
• Create new encrypted volumes from the golden snapshot
• Need to resize the filesystem in the init container (as per
Kubernetes 1.19)
• Recent fix by AWS: https://github.com/kubernetes/kubernetes/
issues/86064
Challenges
AWS bugs
Big encrypted EBS volumes
Challenges
AWS bugs
Big encrypted EBS volumes
$ kubectl get statefulset l0c154j810-an | jq
'.spec.volumeClaimTemplates[0].spec'
{
"accessModes": [
"ReadWriteOnce"
],
"dataSource": {
"apiGroup": "snapshot.storage.k8s.io",
"kind": "VolumeSnapshot",
"name": "golden-snapshot--wsboilqtlr"
},
"resources": {
"requests": {
"storage": "2500Gi"
}
},
"storageClassName": "ebs-sc",
"volumeMode": "Filesystem"
}
Challenges
AWS bugs • Fewer bugs :-)
• Improved support for VolumeSnapshots, e.g. provisioning
volumes across namespaces, resizing a filesystem when
provisioning from a snapshot
Wishlist
• AWS EBS and other PersistentVolume implementations only
allow volume size increments.
• A volume autoscaler (Timescale service) may decide to
increase the volume upon a data ingestion
• When data is subsequently compressed the customer doesn’t
need to pay for a bigger volume
Challenges
Volume resize
Volume size can only be increased, not decreased
• Solution: provide a functionality to fork a service
• A fork is a clone of a service with possibly different CPU and
storage specs
• A fork is implemented by restoring another instance from the
backup of the original one, taken from S3
Challenges
Volume resize
Volume size can only be increased, not decreased
• Native volume downsize
• Kubernetes support, possibly with custom checks from K8s to
determine this is possible.
• Support for volume resizing in a statefulset
Challenges
Volume resize
Wishlist
Thank you!
#AlwaysBeLaunching
Feedback and Questions:
oleksii@timescale.com
Twitter: @hintbits

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
NGINX基本セミナー(セキュリティ編)~NGINXでセキュアなプラットフォームを実現する方法!
 
Apache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel QuarkusApache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel Quarkus
 
Kubernetes #1 intro
Kubernetes #1   introKubernetes #1   intro
Kubernetes #1 intro
 
CloudStack再入門!15分でおさらいするCloudStackの基礎
CloudStack再入門!15分でおさらいするCloudStackの基礎CloudStack再入門!15分でおさらいするCloudStackの基礎
CloudStack再入門!15分でおさらいするCloudStackの基礎
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
 
Deep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instancesDeep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instances
 
"Yahoo! JAPAN の Kubernetes-as-a-Service" で加速するアプリケーション開発
"Yahoo! JAPAN の Kubernetes-as-a-Service" で加速するアプリケーション開発"Yahoo! JAPAN の Kubernetes-as-a-Service" で加速するアプリケーション開発
"Yahoo! JAPAN の Kubernetes-as-a-Service" で加速するアプリケーション開発
 
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration Service20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
 
Dockerからcontainerdへの移行
Dockerからcontainerdへの移行Dockerからcontainerdへの移行
Dockerからcontainerdへの移行
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
 
AWS Black Belt Online Seminar Amazon Aurora
AWS Black Belt Online Seminar Amazon AuroraAWS Black Belt Online Seminar Amazon Aurora
AWS Black Belt Online Seminar Amazon Aurora
 
binary log と 2PC と Group Commit
binary log と 2PC と Group Commitbinary log と 2PC と Group Commit
binary log と 2PC と Group Commit
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
 
ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方ストリーム処理を支えるキューイングシステムの選び方
ストリーム処理を支えるキューイングシステムの選び方
 
[스마트스터디]MongoDB 의 역습
[스마트스터디]MongoDB 의 역습[스마트스터디]MongoDB 의 역습
[스마트스터디]MongoDB 의 역습
 
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교  및 구축 방법
[오픈소스컨설팅] 쿠버네티스와 쿠버네티스 on 오픈스택 비교 및 구축 방법
 
5.6 以前の InnoDB Flushing
5.6 以前の InnoDB Flushing5.6 以前の InnoDB Flushing
5.6 以前の InnoDB Flushing
 
AWS SAMで始めるサーバーレスアプリケーション開発
AWS SAMで始めるサーバーレスアプリケーション開発AWS SAMで始めるサーバーレスアプリケーション開発
AWS SAMで始めるサーバーレスアプリケーション開発
 
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
【NGINXセミナー】 NGINXのWAFとは?その使い方と設定方法 解説セミナー
 

Similar a What we've learned from running a PostgreSQL managed service on Kubernetes

Similar a What we've learned from running a PostgreSQL managed service on Kubernetes (20)

Nordic infrastructure Conference 2017 - SQL Server in DevOps
Nordic infrastructure Conference 2017 - SQL Server in DevOpsNordic infrastructure Conference 2017 - SQL Server in DevOps
Nordic infrastructure Conference 2017 - SQL Server in DevOps
 
JITServerTalk Nebraska 2023.pdf
JITServerTalk Nebraska 2023.pdfJITServerTalk Nebraska 2023.pdf
JITServerTalk Nebraska 2023.pdf
 
Kubernetes Manchester - 6th December 2018
Kubernetes Manchester - 6th December 2018Kubernetes Manchester - 6th December 2018
Kubernetes Manchester - 6th December 2018
 
ECS and Docker at Okta
ECS and Docker at OktaECS and Docker at Okta
ECS and Docker at Okta
 
JPrime_JITServer.pptx
JPrime_JITServer.pptxJPrime_JITServer.pptx
JPrime_JITServer.pptx
 
Database as a Service (DBaaS) on Kubernetes
Database as a Service (DBaaS) on KubernetesDatabase as a Service (DBaaS) on Kubernetes
Database as a Service (DBaaS) on Kubernetes
 
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)
 
Kubernetes & Google Container Engine @ mabl
Kubernetes & Google Container Engine @ mablKubernetes & Google Container Engine @ mabl
Kubernetes & Google Container Engine @ mabl
 
Javaland_JITServerTalk.pptx
Javaland_JITServerTalk.pptxJavaland_JITServerTalk.pptx
Javaland_JITServerTalk.pptx
 
Kubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical ViewKubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical View
 
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
PGConf.ASIA 2019 Bali - Building PostgreSQL as a Service with Kubernetes - Ta...
 
Continuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with KubernetesContinuous Delivery the hard way with Kubernetes
Continuous Delivery the hard way with Kubernetes
 
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
Running Oracle EBS in the cloud (OAUG Collaborate 18 edition)
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
 
Bug smash day magnum
Bug smash day magnumBug smash day magnum
Bug smash day magnum
 
Bug smash day magnum
Bug smash day magnumBug smash day magnum
Bug smash day magnum
 
Containers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. KubernetesContainers orchestrators: Docker vs. Kubernetes
Containers orchestrators: Docker vs. Kubernetes
 
[GS네오텍] Google Kubernetes Engine
[GS네오텍]  Google Kubernetes Engine [GS네오텍]  Google Kubernetes Engine
[GS네오텍] Google Kubernetes Engine
 
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech TalksDesign, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
Design, Deploy, and Optimize SQL Server on AWS - June 2017 AWS Online Tech Talks
 
Serverless in Java Lessons learnt
Serverless in Java Lessons learntServerless in Java Lessons learnt
Serverless in Java Lessons learnt
 

Más de DoKC

The Kubernetes Native Database
The Kubernetes Native DatabaseThe Kubernetes Native Database
The Kubernetes Native Database
DoKC
 
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
DoKC
 
We will Dok You! - The journey to adopt stateful workloads on k8s
We will Dok You! - The journey to adopt stateful workloads on k8sWe will Dok You! - The journey to adopt stateful workloads on k8s
We will Dok You! - The journey to adopt stateful workloads on k8s
DoKC
 
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
DoKC
 

Más de DoKC (20)

Distributed Vector Databases - What, Why, and How
Distributed Vector Databases - What, Why, and HowDistributed Vector Databases - What, Why, and How
Distributed Vector Databases - What, Why, and How
 
Is It Safe? Security Hardening for Databases Using Kubernetes Operators
Is It Safe? Security Hardening for Databases Using Kubernetes OperatorsIs It Safe? Security Hardening for Databases Using Kubernetes Operators
Is It Safe? Security Hardening for Databases Using Kubernetes Operators
 
Stop Worrying and Keep Querying, Using Automated Multi-Region Disaster Recovery
Stop Worrying and Keep Querying, Using Automated Multi-Region Disaster RecoveryStop Worrying and Keep Querying, Using Automated Multi-Region Disaster Recovery
Stop Worrying and Keep Querying, Using Automated Multi-Region Disaster Recovery
 
Transforming Data Processing with Kubernetes: Journey Towards a Self-Serve Da...
Transforming Data Processing with Kubernetes: Journey Towards a Self-Serve Da...Transforming Data Processing with Kubernetes: Journey Towards a Self-Serve Da...
Transforming Data Processing with Kubernetes: Journey Towards a Self-Serve Da...
 
The State of Stateful on Kubernetes
The State of Stateful on KubernetesThe State of Stateful on Kubernetes
The State of Stateful on Kubernetes
 
Colocating Data Workloads and Web Services on Kubernetes to Improve Resource ...
Colocating Data Workloads and Web Services on Kubernetes to Improve Resource ...Colocating Data Workloads and Web Services on Kubernetes to Improve Resource ...
Colocating Data Workloads and Web Services on Kubernetes to Improve Resource ...
 
Make Your Kafka Cluster Production-Ready
Make Your Kafka Cluster Production-ReadyMake Your Kafka Cluster Production-Ready
Make Your Kafka Cluster Production-Ready
 
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
Dynamic Large Scale Spark on Kubernetes: Empowering the Community with Argo W...
 
Run PostgreSQL in Warp Speed Using NVMe/TCP in the Cloud
Run PostgreSQL in Warp Speed Using NVMe/TCP in the CloudRun PostgreSQL in Warp Speed Using NVMe/TCP in the Cloud
Run PostgreSQL in Warp Speed Using NVMe/TCP in the Cloud
 
The Kubernetes Native Database
The Kubernetes Native DatabaseThe Kubernetes Native Database
The Kubernetes Native Database
 
ING Data Services hosted on ICHP DoK Amsterdam 2023
ING Data Services hosted on ICHP DoK Amsterdam 2023ING Data Services hosted on ICHP DoK Amsterdam 2023
ING Data Services hosted on ICHP DoK Amsterdam 2023
 
Implementing data and databases on K8s within the Dutch government
Implementing data and databases on K8s within the Dutch governmentImplementing data and databases on K8s within the Dutch government
Implementing data and databases on K8s within the Dutch government
 
StatefulSets in K8s - DoK Talks #154
StatefulSets in K8s - DoK Talks #154StatefulSets in K8s - DoK Talks #154
StatefulSets in K8s - DoK Talks #154
 
Analytics with Apache Superset and ClickHouse - DoK Talks #151
Analytics with Apache Superset and ClickHouse - DoK Talks #151Analytics with Apache Superset and ClickHouse - DoK Talks #151
Analytics with Apache Superset and ClickHouse - DoK Talks #151
 
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
Overcoming challenges with protecting and migrating data in multi-cloud K8s e...
 
Evaluating Cloud Native Storage Vendors - DoK Talks #147
Evaluating Cloud Native Storage Vendors - DoK Talks #147Evaluating Cloud Native Storage Vendors - DoK Talks #147
Evaluating Cloud Native Storage Vendors - DoK Talks #147
 
Kubernetes Cluster Upgrade Strategies and Data: Best Practices for your State...
Kubernetes Cluster Upgrade Strategies and Data: Best Practices for your State...Kubernetes Cluster Upgrade Strategies and Data: Best Practices for your State...
Kubernetes Cluster Upgrade Strategies and Data: Best Practices for your State...
 
We will Dok You! - The journey to adopt stateful workloads on k8s
We will Dok You! - The journey to adopt stateful workloads on k8sWe will Dok You! - The journey to adopt stateful workloads on k8s
We will Dok You! - The journey to adopt stateful workloads on k8s
 
Mastering MongoDB on Kubernetes, the power of operators
Mastering MongoDB on Kubernetes, the power of operators Mastering MongoDB on Kubernetes, the power of operators
Mastering MongoDB on Kubernetes, the power of operators
 
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
Leveraging Running Stateful Workloads on Kubernetes for the Benefit of Develo...
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

What we've learned from running a PostgreSQL managed service on Kubernetes

  • 1. Running a managed service on Kubernetes and PostgreSQL What we learned at Timescale DoK Day Europe, May 16th, 2022 Oleksii Kliukin
  • 2. TimescaleDB is PostgreSQL, supercharged for time-series data and analytics.
  • 3. TimescaleDB is free and open PostgreSQL extension
  • 4. Timescale Cloud is a hosted and fully managed TimescaleDB running on Kubernetes
  • 7.
  • 8. Timescale cloud DB on Kubernetes / AWS
  • 10. • Timescale continuous/real-time aggregates may require a lot of memory. Out of memory (OOM) when limits are set low is not uncommon. • OOM behavior assumed by PostgreSQL developers:
 
 • Linux OOM killer: SIGKILL a random Postgres process • A backend process is killed: disruption, restart of every connection • A postmaster is killed: unclean shutdown, in extreme cases to startup instance Challenges OOM killer OOM causes abrupt shutdown of PostgreSQL ERROR: out of memory on a request of 1024 bytes
  • 11. Challenges OOM killer OOM causes abrupt shutdown of PostgreSQL $ kubectl get pod tinyforkv01-an-0 -o json jq '.spec.containers[0].resources' { "limits": { "cpu": "4", "memory": "1Gi" }, "requests": { "cpu": "4", "memory": "1Gi" } }
  • 12. Challenges OOM killer OOM causes abrupt shutdown of PostgreSQL * Image source: user MesserWoland, https://en.m.wikipedia.org/wiki/File:The_death.svg *
  • 13. • Regular PostgreSQL: set memory overcommit, enable swap • vm.overcommit_memory = 2 • Can’t set it individually per container • A node typically runs some pods (eg. daemonsets for logging) incompatible with this setting
 
 https://github.com/kubernetes/kubernetes/issues/90973 Challenges OOM killer OOM causes abrupt shutdown of PostgreSQL
  • 14. • Solution: OOMGuard library collects statistics on the memory usage, overriding malloc • Use LD_PRELOAD_LIBRARY to install it for Postgres processes • Can just report statics, or actually block allocations going above the predefined threshold, emulating regular malloc behavior • OOM_GUARD_LIMIT threshold is derived from the container memory limit, accounting for shared_buffers and OS overhead. Challenges OOM killer OOM causes abrupt shutdown of PostgreSQL
  • 15. • PostgreSQL: provide memory allocation hooks to do internal accounting and deny allocations via extensions. • Linux/Kubernetes: configure oom_adj_score and vm_overcommit per cgroup on the Linux/Kubernetes layer. • Improved debugging experience (locating debug symbols from the container when running perf or gdb on the host) Challenges OOM killer Wishlist
  • 16. • New versions of Timescale extension are released regularly • A new timescale-docker-ha image is built once the extension is released • We want to deliver latest extension (but not necessary auto- upgrade) to our customers immediately • Changing pod’s docker image requires a pod restart • Planned customer downtime may only happen during maintenance window, only a few times a year Challenges Fewer downtimes Extension updates require a pod bounce
  • 18. • Solution: hot-forge • A binary inside the container to fetch pre-packaged bundles and put them in the container • The bundles are delivered using a postgres connection (COPY TO PROGRAM) • The bundles are written to a persistent volume and linked to a container filesystem • Mostly adding new data (although can potentially replace/delete existing files in the container) Challenges Fewer downtimes Extension updates require a pod bounce
  • 19. • Allow bouncing of individual containers in the pod and changing the docker image • Support “mutable” area inside the pod to deliver updates. Challenges Fewer downtimes Wishlist
  • 20. • Etcd is a core of the Kubernetes cluster • Consists of multiple nodes (we run 5) - should be resilient? • Can degrade on master node updates • Performance issues (EBS burst balance, too many objects) • Patroni dependency (no Kubernetes API - instances are read- only) Challenges Operating Etcd Etcd is a 5-nodes single point of failure Image source: Andy Langager, https://www.flickr.com/photos/andylangager/8631388149
  • 21. • Solution: no silver bullet • Many small clusters in each region instead of a single big one • Etcd performance monitoring • Fire drills on ephemeral clusters • Solution: Patroni experimental static_primary mode: • Enforce single primary by rejecting connections from other nodes • Do not demote when Kubernetes API is not available Challenges Operating Etcd Etcd is a 5-nodes single point of failure
  • 22. • Some operational instructions when Etcd is down • Better observability inside Etcd • Patroni “isolated” mode scalable to any number of pods Challenges Operating Etcd Wishlist
  • 23. • New (1TB+) encrypted EBS volumes show an existing partition marker (Atari partition) • Kubernetes refuses to format them • Pod is stuck at startup Challenges AWS bugs Encrypted EBS volumes Image source: Bill Bertram, https://commons.wikimedia.org/wiki/File:Atari_1040STf.jpg
  • 24. • Solution: create a small 1GB encrypted volume • Snapshot it into a “golden snapshot” • Create new encrypted volumes from the golden snapshot • Need to resize the filesystem in the init container (as per Kubernetes 1.19) • Recent fix by AWS: https://github.com/kubernetes/kubernetes/ issues/86064 Challenges AWS bugs Big encrypted EBS volumes
  • 25. Challenges AWS bugs Big encrypted EBS volumes $ kubectl get statefulset l0c154j810-an | jq '.spec.volumeClaimTemplates[0].spec' { "accessModes": [ "ReadWriteOnce" ], "dataSource": { "apiGroup": "snapshot.storage.k8s.io", "kind": "VolumeSnapshot", "name": "golden-snapshot--wsboilqtlr" }, "resources": { "requests": { "storage": "2500Gi" } }, "storageClassName": "ebs-sc", "volumeMode": "Filesystem" }
  • 26. Challenges AWS bugs • Fewer bugs :-) • Improved support for VolumeSnapshots, e.g. provisioning volumes across namespaces, resizing a filesystem when provisioning from a snapshot Wishlist
  • 27. • AWS EBS and other PersistentVolume implementations only allow volume size increments. • A volume autoscaler (Timescale service) may decide to increase the volume upon a data ingestion • When data is subsequently compressed the customer doesn’t need to pay for a bigger volume Challenges Volume resize Volume size can only be increased, not decreased
  • 28. • Solution: provide a functionality to fork a service • A fork is a clone of a service with possibly different CPU and storage specs • A fork is implemented by restoring another instance from the backup of the original one, taken from S3 Challenges Volume resize Volume size can only be increased, not decreased
  • 29. • Native volume downsize • Kubernetes support, possibly with custom checks from K8s to determine this is possible. • Support for volume resizing in a statefulset Challenges Volume resize Wishlist