Kubernetes Application Management: Stateful Services

Background

Use StatefulSets to Deploy MySQL

StatefulSet Overview

Service Deployment

ConfigMap

Headless Service

ClusterIP Service

StatefulSet

  • The init-mysql container generates configuration files. It extracts the Pod ordinal from the hostname and exports the ordinal into the /mnt/conf.d/server-id.cnf file. It also applies either master.cnf or slave.cnf (depending on the node type) from the ConfigMap by copying the contents into /mnt/conf.
  • The clone-mysql container clones data. The clone-mysql container in Pod N+1 clones data from Pod N to the PersistentVolume bound.
  • After the Init Containers complete successfully, the app containers run. The mysql container runs the actual mysqld server.
  • The xtrabackup container acts as a sidecar. It waits for mysqld in the mysql container to be ready and then runs the START SLAVE command to initialize data replication on the slave. The xtrabackup container also listens for connections from other Pods requesting a data clone.
  • The StatefulSet associates a unique PC to each Pod by using volumeClaimTemplates. In this sample, Pod Nis associated to a PVC named data-mysql-N, which is also bound to the PV provided by the storage system. This mechanism ensures that a rescheduled Pod can still mount the original data.

Service Maintenance

Service Fault Recovery

Service Scaling

Kubectl scale statefulset mysql -- replicas = <NumOfReplicas>

Service Status Monitoring

Data Backup and Recovery

Use Volume Interfaces

Use VolumeSnapshots

Deploy MySQL by Using Operators

Operator Introduction

Oracle MySQL Operator

How the Oracle MySQL Operator Works

  • Primary: In this mode, the service group consists of a read-write single-primary node and multiple read-only primary nodes.
  • Multi-Primary: In multi-primary mode, each node in the cluster plays the same role and the notion of primary-secondary does not apply. Each node can process read/write requests from users.

Service Deployment

apiVersion: mysql.oracle.com/v1alpha1
kind: Cluster
metadata:
name: mysql-multimaster-cluster
spec:
multiMaster: true
members: 3

Service Maintenance

Service Fault Recovery

Service Scaling

Service Status Monitoring

Data Backup and Recovery

[...]
kind: BackupSchedule
spec:
schedule: '*/30 * * * *'
backupTemplate:
cluster:
name: mysql-cluster
executor:
provider: mysqldump
databases:
- test
[...]

Summary

References

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Raspberry Pi VPN Router.

Simplifying the World of Microservices and Container Technology

How Can You Create Customizable Products In Shopify Without An App?

Why Documentation is the Next Big Thing

The problem with sharding

How to Create and Use Secrets in KubernetesHow to Create and Use Secrets in Kubernetes

Odysseus — Your Friendly DNS Pathfinder

Build a Custom Paint Flutter App Widget

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Deploy a Microservice into Istio service mesh

This image has an empty alt attribute; its file name is image.png

Traffic routing using istio service mesh

Service Mesh Architecture

AWS ElastiCache(Redis) With TLS