SlideShare a Scribd company logo
NOVEMBER 6, 2019
Creating a stateful application with
K8S and AWS DB Services
Bahubali Shetti
@Shetti
Director of Cloud Developer Advocacy VMware
App
Cloud
Database
Kubernetes
? Self or Fully Manage
Stateless
Application Data
(Application State)
Not easy to move
Maximizing portability with Kubernetes – BUT what about the Data?
Self Managed vs Fully Managed….
?
Find it at cloudjourney.io (look for the github site)
Typical Microservice App - AcmeShop
Parameterizing the database end points in K8S
Code Instrumentation for App-DB connectivity
...
…
spec:
volumes:
- name: acmefit-order-data
emptyDir: {}
containers:
- image: order:latest
name: order
env:
- name: ORDER_DB_HOST
value: 'order-mongo'
- name: ORDER_DB_PASSWORD
valueFrom:
secretKeyRef:
name: order-mongo-pass
key: password
- name: ORDER_DB_PORT
value: '27017’
…
…
FROM bitnami/python:3.7
MAINTAINER Bill Shetti
"billshetti@gmail.com"
ENV ORDER_DB_HOST="localhost"
ENV ORDER_DB_PORT="27017"
ENV ORDER_DB_PASSWORD=""
ENV ORDER_DB_USERNAME=""
ENV PAYMENT_HOST="localhost"
ENV PAYMENT_PORT="9000"
# needed for mongo client
RUN install_packages mongodb-
clients
COPY ./requirements.txt
/app/requirements.txt
RUN pip3 install -r requirements.txt
…
…
…
…
from os import environ
if environ.get('ORDER_DB_USERNAME') is not
None:
if os.environ['ORDER_DB_USERNAME'] !=
"":
mongouser=os.environ['ORDER_DB_USERNA
ME']
else:
mongouser=''
else:
mongouser=''
if environ.get('ORDER_DB_HOST') is not None:
if os.environ['ORDER_DB_HOST'] != "":
mongohost=os.environ['ORDER_DB_HOST']
else:
mongohost='localhost'
else:
mongohost='localhost’
…
…
K8S Yaml Dockerfile Python order.py code
Libraries and connecting to the DB
Code Instrumentation for DB
import pymongo
from pymongo import MongoClient
from pymongo import errors as mongoerrors
client=MongoClient(mongouri)
#uri=username:password@host:port
Or
client=MongoClient(host=mongohost, port=int(mongoport),
username=mongouser, password=mongopassword)
import redis
rConn=redis.StrictRedis(host=redishost, port=redisport,
password=redispassword, db=0)
Lots of standard libraries (go, python, etc) with significant support
Installation and management – Several options
Setting up your own containerized DB
Initialization
kubectl create secret generic order-mongo-pass
--from-literal=password=<value>
Secrets
Create
kubectl apply -f order-db-total.yaml
kubectl apply -f config-map.yaml
Automates deployment of single node
or replica sets for mongodb
Enables set up of alerting, monitoring
Optional persistence and storage
configuration
Easy scale
(ISH)
OperatorsSimple K8S Create
Early Days
(Beta/Alpha)
(still adding features)
etc
(ISH)
Installation and management – Several options
Setting up your own containerized DB
HA Configured by default
So what’s hard? – Keeping state persistent
Setting up your own containerized DB
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast
provisioner: kubernetes.io/aws-ebs
parameters:
type: io1
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "fast"
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 100Gi
Storage Provisioning and Management
Infra and DB expertise or App and business focus?
What’s important to you?
Infra Skills App Skills
?
AWS Options
Fully Managed Databases
Simple to implement
Creating HA arch – operational overhead
No support for sharding
No encryption
Operationally Expensive
Simple to implement
Built in HA with read replicas, multiple primaries, failovers, etc
Easly scalable
Sharding support
Encryption at rest/intransit
K8S
Operator
VS
√
Redis and AWS Elasticache
Managed Databases
Built in sharding & replica sets for easy scaling
Still have to manually add nodes
Manage backup manually or with tools (OpsManager, CloudManager etc)
Manage Upgrades etc
K8S
Operator
Easy setup (only compatible with MongoDB 3.6)
Managed sharding, replicas
Managed scale (up to 64TB)
Easy backups - AWS
Handles 100ks reads/writes/sec
Easy setup – deploys on AWS/Azure/GCP
Managed sharding, replicas
Managed scale
Easy backups – AWS/Azure/GCP
Pure Mongo experience with latest and greatest features
VS
√
√
DocumentDB and MongoDB Atlas
Managed Databases
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast
provisioner: kubernetes.io/aws-ebs
parameters:
type: io1
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "fast"
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 100Gi
Storage Provisioning and Management
Keeping state persistent?
Using a managedDB
aws --region us-east-2 elasticache create-cache-cluster --cache-cluster-id my-cluster --cache-node-type cache.r4.large --
engine redis --engine-version 3.2.4 --num-cache-nodes 1 --cache-parameter-group default.redis3.2
aws --region us-east-2 docdb create-db-cluster --db-cluster-identifier mongoeq --engine docdb --master-username bill --
master-user-password password1
OR
https://github.com/awslabs/aws-service-operator
AWS CLI with automation
AWS service operator
(ISH)
Installation and management –
Using a managed DB
Parameterizing the database end points in K8S
Code Instrumentation for DB
...
…
spec:
volumes:
- name: acmefit-order-data
emptyDir: {}
containers:
- image: order:latest
name: order
env:
- name: ORDER_DB_HOST
value: 'order-mongo'
- name: ORDER_DB_PASSWORD
valueFrom:
secretKeyRef:
name: order-mongo-pass
key: password
- name: ORDER_DB_PORT
value: '27017’
…
…
FROM bitnami/python:3.7
MAINTAINER Bill Shetti
"billshetti@gmail.com"
ENV ORDER_DB_HOST="localhost"
ENV ORDER_DB_PORT="27017"
ENV ORDER_DB_PASSWORD=""
ENV ORDER_DB_USERNAME=""
ENV PAYMENT_HOST="localhost"
ENV PAYMENT_PORT="9000"
# needed for mongo client
RUN install_packages mongodb-
clients
COPY ./requirements.txt
/app/requirements.txt
RUN pip3 install -r requirements.txt
…
…
…
…
from os import environ
if environ.get('ORDER_DB_USERNAME') is not
None:
if os.environ['ORDER_DB_USERNAME'] !=
"":
mongouser=os.environ['ORDER_DB_USERNA
ME']
else:
mongouser=''
else:
mongouser=''
if environ.get('ORDER_DB_HOST') is not None:
if os.environ['ORDER_DB_HOST'] != "":
mongohost=os.environ['ORDER_DB_HOST']
else:
mongohost='localhost'
else:
mongohost='localhost’
…
…
K8S Yaml Dockerfile Python order.py code
Insert Document DB URL INFO HERE
import pymongo
from pymongo import MongoClient
from pymongo import errors as mongoerrors
client=MongoClient(mongouri)
#uri=username:password@host:port
Or
client=MongoClient(host=mongohost, port=int(mongoport),
username=mongouser, password=mongopassword)
import redis
rConn=redis.StrictRedis(host=redishost, port=redisport,
password=redispassword, db=0)
Steps and hurdles – code instrumentization
Using a Managed DB
URL FROM AWS Services
Self Managed vs Fully Managed….
?
19
www.cloudjourney.io
@cloudjourneyio
Bahubali Shetti - @Shetti
How to manage state with a Kubernetes Application

More Related Content

PDF
O'Reilly Webcast: Architecting Applications For The Cloud
PDF
Deploying a Java Application on Azure Kubernetes Service with Cosmos DB
PDF
Scaling drupal on amazon web services dr
PDF
Apache Superset at Airbnb
PPTX
Leverage Azure Blob Storage to build storage intensive cloud native applications
PPTX
Deploy Elasticsearch Cluster on Kubernetes
PDF
AWS UG Greece meetup #1
PDF
BI Meets Serverless on Cloud
O'Reilly Webcast: Architecting Applications For The Cloud
Deploying a Java Application on Azure Kubernetes Service with Cosmos DB
Scaling drupal on amazon web services dr
Apache Superset at Airbnb
Leverage Azure Blob Storage to build storage intensive cloud native applications
Deploy Elasticsearch Cluster on Kubernetes
AWS UG Greece meetup #1
BI Meets Serverless on Cloud

What's hot (20)

PPTX
Windows Azure HDInsight Service
PDF
Serverless Stream Processing with Bill Bejeck
ODP
Hosting Drupal on Amazon EC2
PPTX
storage on windows azure
PDF
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
PPTX
A practical approach to provisioning resources in azure
PPTX
Node.js on Windows Azure
PDF
Rich storytelling with Drupal, Paragraphs and Islandora DAMS
PDF
Amazon Web Services Building Blocks for Drupal Applications and Hosting
PDF
ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...
PPTX
Kubernetes talk at DDDSydney 2017
PPTX
Scalable On-Demand Hadoop Clusters with Docker and Mesos
PDF
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
PDF
Webapp on AWS
PDF
Cloud Computing: AWS for Lean Startups
PPTX
Global Windows Azure Bootcamp (GWAB) Auckland 2014 - Windows Azure Integrati...
PPTX
Azure CosmosDB
PPTX
Create HDInsight Cluster in Azure Portal (February 2015)
PPTX
Binary Studio Academy 2016. MS Azure. Cloud hosting.
PPTX
GDG Ternopil TechTalks Web #1 2015 - Data storages in Microsoft Azure
Windows Azure HDInsight Service
Serverless Stream Processing with Bill Bejeck
Hosting Drupal on Amazon EC2
storage on windows azure
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
A practical approach to provisioning resources in azure
Node.js on Windows Azure
Rich storytelling with Drupal, Paragraphs and Islandora DAMS
Amazon Web Services Building Blocks for Drupal Applications and Hosting
ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...
Kubernetes talk at DDDSydney 2017
Scalable On-Demand Hadoop Clusters with Docker and Mesos
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Webapp on AWS
Cloud Computing: AWS for Lean Startups
Global Windows Azure Bootcamp (GWAB) Auckland 2014 - Windows Azure Integrati...
Azure CosmosDB
Create HDInsight Cluster in Azure Portal (February 2015)
Binary Studio Academy 2016. MS Azure. Cloud hosting.
GDG Ternopil TechTalks Web #1 2015 - Data storages in Microsoft Azure
Ad

Similar to How to manage state with a Kubernetes Application (20)

PDF
MongoDB OpsManager and Kubernetes
PDF
YugabyteDB - Distributed SQL Database on Kubernetes
PPTX
Best practices: running high-performance databases on Kubernetes
PDF
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
PPTX
Database as a Service (DBaaS) on Kubernetes
PDF
Running a database on local NVMes on Kubernetes
PDF
Running a database on local NVMes on Kubernetes
PDF
MongoDB World 2019: Mastering MongoDB in Kubernetes
PDF
MongoDB Ops Manager + Kubernetes
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
Cloud Data Strategy event London
PDF
Deploying PostgreSQL on Kubernetes
PPT
Kubernetes for Cloud-Native Environments
PDF
MongoDB .local Munich 2019: Mastering MongoDB on Kubernetes – MongoDB Enterpr...
PPTX
Webinar: Data Streaming with Apache Kafka & MongoDB
PPTX
Data Streaming with Apache Kafka & MongoDB - EMEA
PDF
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
KEY
Discover MongoDB - Israel
PPTX
Webinar: Enterprise Trends for Database-as-a-Service
PDF
A guide of PostgreSQL on Kubernetes
MongoDB OpsManager and Kubernetes
YugabyteDB - Distributed SQL Database on Kubernetes
Best practices: running high-performance databases on Kubernetes
SREDAY London 2024 | Cloud Native Technologies: The Building Blocks of Modern...
Database as a Service (DBaaS) on Kubernetes
Running a database on local NVMes on Kubernetes
Running a database on local NVMes on Kubernetes
MongoDB World 2019: Mastering MongoDB in Kubernetes
MongoDB Ops Manager + Kubernetes
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
Cloud Data Strategy event London
Deploying PostgreSQL on Kubernetes
Kubernetes for Cloud-Native Environments
MongoDB .local Munich 2019: Mastering MongoDB on Kubernetes – MongoDB Enterpr...
Webinar: Data Streaming with Apache Kafka & MongoDB
Data Streaming with Apache Kafka & MongoDB - EMEA
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
Discover MongoDB - Israel
Webinar: Enterprise Trends for Database-as-a-Service
A guide of PostgreSQL on Kubernetes
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPT
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation theory and applications.pdf
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
MIND Revenue Release Quarter 2 2025 Press Release
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Group 1 Presentation -Planning and Decision Making .pptx
Teaching material agriculture food technology

How to manage state with a Kubernetes Application

  • 1. NOVEMBER 6, 2019 Creating a stateful application with K8S and AWS DB Services Bahubali Shetti @Shetti Director of Cloud Developer Advocacy VMware
  • 2. App Cloud Database Kubernetes ? Self or Fully Manage Stateless Application Data (Application State) Not easy to move Maximizing portability with Kubernetes – BUT what about the Data?
  • 3. Self Managed vs Fully Managed…. ?
  • 4. Find it at cloudjourney.io (look for the github site) Typical Microservice App - AcmeShop
  • 5. Parameterizing the database end points in K8S Code Instrumentation for App-DB connectivity ... … spec: volumes: - name: acmefit-order-data emptyDir: {} containers: - image: order:latest name: order env: - name: ORDER_DB_HOST value: 'order-mongo' - name: ORDER_DB_PASSWORD valueFrom: secretKeyRef: name: order-mongo-pass key: password - name: ORDER_DB_PORT value: '27017’ … … FROM bitnami/python:3.7 MAINTAINER Bill Shetti "billshetti@gmail.com" ENV ORDER_DB_HOST="localhost" ENV ORDER_DB_PORT="27017" ENV ORDER_DB_PASSWORD="" ENV ORDER_DB_USERNAME="" ENV PAYMENT_HOST="localhost" ENV PAYMENT_PORT="9000" # needed for mongo client RUN install_packages mongodb- clients COPY ./requirements.txt /app/requirements.txt RUN pip3 install -r requirements.txt … … … … from os import environ if environ.get('ORDER_DB_USERNAME') is not None: if os.environ['ORDER_DB_USERNAME'] != "": mongouser=os.environ['ORDER_DB_USERNA ME'] else: mongouser='' else: mongouser='' if environ.get('ORDER_DB_HOST') is not None: if os.environ['ORDER_DB_HOST'] != "": mongohost=os.environ['ORDER_DB_HOST'] else: mongohost='localhost' else: mongohost='localhost’ … … K8S Yaml Dockerfile Python order.py code
  • 6. Libraries and connecting to the DB Code Instrumentation for DB import pymongo from pymongo import MongoClient from pymongo import errors as mongoerrors client=MongoClient(mongouri) #uri=username:password@host:port Or client=MongoClient(host=mongohost, port=int(mongoport), username=mongouser, password=mongopassword) import redis rConn=redis.StrictRedis(host=redishost, port=redisport, password=redispassword, db=0) Lots of standard libraries (go, python, etc) with significant support
  • 7. Installation and management – Several options Setting up your own containerized DB Initialization kubectl create secret generic order-mongo-pass --from-literal=password=<value> Secrets Create kubectl apply -f order-db-total.yaml kubectl apply -f config-map.yaml Automates deployment of single node or replica sets for mongodb Enables set up of alerting, monitoring Optional persistence and storage configuration Easy scale (ISH) OperatorsSimple K8S Create Early Days (Beta/Alpha) (still adding features) etc (ISH)
  • 8. Installation and management – Several options Setting up your own containerized DB HA Configured by default
  • 9. So what’s hard? – Keeping state persistent Setting up your own containerized DB apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: fast provisioner: kubernetes.io/aws-ebs parameters: type: io1 containers: - name: mongo image: mongo ports: - containerPort: 27017 volumeMounts: - name: mongo-persistent-storage mountPath: /data/db volumeClaimTemplates: - metadata: name: mongo-persistent-storage annotations: volume.beta.kubernetes.io/storage-class: "fast" spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 100Gi Storage Provisioning and Management
  • 10. Infra and DB expertise or App and business focus? What’s important to you? Infra Skills App Skills ?
  • 12. Simple to implement Creating HA arch – operational overhead No support for sharding No encryption Operationally Expensive Simple to implement Built in HA with read replicas, multiple primaries, failovers, etc Easly scalable Sharding support Encryption at rest/intransit K8S Operator VS √ Redis and AWS Elasticache Managed Databases
  • 13. Built in sharding & replica sets for easy scaling Still have to manually add nodes Manage backup manually or with tools (OpsManager, CloudManager etc) Manage Upgrades etc K8S Operator Easy setup (only compatible with MongoDB 3.6) Managed sharding, replicas Managed scale (up to 64TB) Easy backups - AWS Handles 100ks reads/writes/sec Easy setup – deploys on AWS/Azure/GCP Managed sharding, replicas Managed scale Easy backups – AWS/Azure/GCP Pure Mongo experience with latest and greatest features VS √ √ DocumentDB and MongoDB Atlas Managed Databases
  • 14. apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: fast provisioner: kubernetes.io/aws-ebs parameters: type: io1 containers: - name: mongo image: mongo ports: - containerPort: 27017 volumeMounts: - name: mongo-persistent-storage mountPath: /data/db volumeClaimTemplates: - metadata: name: mongo-persistent-storage annotations: volume.beta.kubernetes.io/storage-class: "fast" spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 100Gi Storage Provisioning and Management Keeping state persistent? Using a managedDB
  • 15. aws --region us-east-2 elasticache create-cache-cluster --cache-cluster-id my-cluster --cache-node-type cache.r4.large -- engine redis --engine-version 3.2.4 --num-cache-nodes 1 --cache-parameter-group default.redis3.2 aws --region us-east-2 docdb create-db-cluster --db-cluster-identifier mongoeq --engine docdb --master-username bill -- master-user-password password1 OR https://github.com/awslabs/aws-service-operator AWS CLI with automation AWS service operator (ISH) Installation and management – Using a managed DB
  • 16. Parameterizing the database end points in K8S Code Instrumentation for DB ... … spec: volumes: - name: acmefit-order-data emptyDir: {} containers: - image: order:latest name: order env: - name: ORDER_DB_HOST value: 'order-mongo' - name: ORDER_DB_PASSWORD valueFrom: secretKeyRef: name: order-mongo-pass key: password - name: ORDER_DB_PORT value: '27017’ … … FROM bitnami/python:3.7 MAINTAINER Bill Shetti "billshetti@gmail.com" ENV ORDER_DB_HOST="localhost" ENV ORDER_DB_PORT="27017" ENV ORDER_DB_PASSWORD="" ENV ORDER_DB_USERNAME="" ENV PAYMENT_HOST="localhost" ENV PAYMENT_PORT="9000" # needed for mongo client RUN install_packages mongodb- clients COPY ./requirements.txt /app/requirements.txt RUN pip3 install -r requirements.txt … … … … from os import environ if environ.get('ORDER_DB_USERNAME') is not None: if os.environ['ORDER_DB_USERNAME'] != "": mongouser=os.environ['ORDER_DB_USERNA ME'] else: mongouser='' else: mongouser='' if environ.get('ORDER_DB_HOST') is not None: if os.environ['ORDER_DB_HOST'] != "": mongohost=os.environ['ORDER_DB_HOST'] else: mongohost='localhost' else: mongohost='localhost’ … … K8S Yaml Dockerfile Python order.py code Insert Document DB URL INFO HERE
  • 17. import pymongo from pymongo import MongoClient from pymongo import errors as mongoerrors client=MongoClient(mongouri) #uri=username:password@host:port Or client=MongoClient(host=mongohost, port=int(mongoport), username=mongouser, password=mongopassword) import redis rConn=redis.StrictRedis(host=redishost, port=redisport, password=redispassword, db=0) Steps and hurdles – code instrumentization Using a Managed DB URL FROM AWS Services
  • 18. Self Managed vs Fully Managed…. ?