项目作者: opencdk8s

项目描述 :
CDK8s construct to create a replicated Redis Statefulset on Kubernetes.
高级语言: TypeScript
项目地址: git://github.com/opencdk8s/cdk8s-redis-sts.git
创建时间: 2021-02-10T16:56:00Z
项目社区:https://github.com/opencdk8s/cdk8s-redis-sts

开源协议:Apache License 2.0

下载


cdk8s-redis-sts

Release
npm version
PyPI version
@opencdk8s/cdk8s-redis-sts?label=npm&color=green" alt="npm">
PyPi

Create a Replicated Redis Statefulset on Kubernetes, powered by the cdk8s project 🚀

Disclaimer

This construct is under heavy development, and breaking changes will be introduced very often. Please don’t forget to version lock your code if you are using this construct.

Overview

cdk8s-redis-sts is a cdk8s library.

  1. import { Construct } from 'constructs';
  2. import { App, Chart, ChartProps } from 'cdk8s';
  3. import { MyRedis } from '@opencdk8s/cdk8s-redis-sts';
  4. export class MyChart extends Chart {
  5. constructor(scope: Construct, id: string, props: ChartProps = { }) {
  6. super(scope, id, props);
  7. new MyRedis(this, 'dev', {
  8. image: 'redis',
  9. namespace: 'databases',
  10. volumeSize: '10Gi',
  11. replicas: 2,
  12. createStorageClass: true,
  13. volumeProvisioner: 'kubernetes.io/aws-ebs',
  14. storageClassName: "io1-slow",
  15. storageClassParams: {
  16. type: 'io1',
  17. fsType: 'ext4',
  18. iopsPerGB: "10",
  19. },
  20. });
  21. }
  22. }
  23. const app = new App();
  24. new MyChart(app, 'dev');
  25. app.synth();

Then the Kubernetes manifests created by cdk8s synth command will have Kubernetes resources such as Statefulset, ConfigMap and Service as follows.


manifest.k8s.yaml

yaml allowVolumeExpansion: true apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: io1-slow parameters: fsType: ext4 iopsPerGB: "10" type: io1 provisioner: kubernetes.io/aws-ebs reclaimPolicy: Retain --- apiVersion: v1 data: master.conf: |- bind 0.0.0.0 daemonize no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 supervised no slave.conf: |- slaveof dev 6379 kind: ConfigMap metadata: name: dev-redis-conf --- apiVersion: v1 kind: Service metadata: labels: app: dev name: dev namespace: databases spec: ports: - port: 6379 targetPort: 6379 selector: app: dev type: ClusterIP --- apiVersion: apps/v1 kind: StatefulSet metadata: labels: app: dev name: dev namespace: databases spec: replicas: 2 selector: matchLabels: app: dev serviceName: dev template: metadata: labels: app: dev spec: containers: - command: - bash - -c - |- [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 ordinal=${BASH_REMATCH[1]} if [[ $ordinal -eq 0 ]]; then redis-server /mnt/redis/master.conf else redis-server /mnt/redis/slave.conf fi env: [] image: redis name: redis ports: - containerPort: 6379 resources: limits: cpu: 400m memory: 512Mi requests: cpu: 200m memory: 256Mi volumeMounts: - mountPath: /data name: dev - mountPath: /mnt/redis/ name: dev-redis-conf terminationGracePeriodSeconds: 10 volumes: - configMap: name: dev-redis-conf name: dev-redis-conf volumeClaimTemplates: - metadata: name: dev namespace: databases spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: io1-slow

Installation

TypeScript

Use yarn or npm to install.

  1. $ npm install @opencdk8s/cdk8s-redis-sts
  1. $ yarn add @opencdk8s/cdk8s-redis-sts

Python

  1. $ pip install cdk8s-redis-sts

Contribution

  1. Fork (link)
  2. Bootstrap the repo:

    1. npx projen # generates package.json
    2. yarn install # installs dependencies
  3. Development scripts:
    |Command|Description
    |-|-
    |yarn compile|Compiles typescript => javascript
    |yarn watch|Watch & compile
    |yarn test|Run unit test & linter through jest
    |yarn test -u|Update jest snapshots
    |yarn run package|Creates a dist with packages for all languages.
    |yarn build|Compile + test + package
    |yarn bump|Bump version (with changelog) based on [conventional commits]
    |yarn release|Bump + push to master
  4. Create a feature branch
  5. Commit your changes
  6. Rebase your local changes against the master branch
  7. Create a new Pull Request (use conventional commits for the title please)

Licence

Apache License, Version 2.0

Author

Hunter-Thompson