Kubernetes StatefulSet with zookeeper
2021/8/26 23:09:52
本文主要是介绍Kubernetes StatefulSet with zookeeper,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
介绍
官方文档https://kubernetes.io/zh/docs/tutorials/stateful-application/zookeeper/
在部署之前,你需要熟悉以下Kubernetes概念
- Pods
- Cluster DNS
- Headless Services
- PersistentVolumes
- PersistentVolume Provisioning
- StatefulSets
- PodDisruptionBudgets
- PodAntiAffinity
- kubectl CLI
根据官方要求,zookeeper部署在Kubernetes集群需要具备如下要求
-
- node节点资源至少四个节点的集群,每个节点至少 2 CPUs 和 4 GiB 内存
如果在云平台部署zookeeper集群,需要学习相关云厂商的持久化存储,如何与Kubernetes集群融合
配置过程
整个部署分为以下几个步骤(为了细化官方文档部署过程,以下具体的分段),官方文档给出的example.yaml有缺少遗漏的部分,在下文一一指出,如下
- 创建StorageClass
- 创建PersistentVolumeClaim
- 创建Headless Service
- 创建PodDisruptionBudget
- 创建StatefulSets
# zookeeper.yaml apiVersion: v1 kind: Service metadata: name: pre-zk-hs namespace: pre labels: app: pre-zk spec: ports: - port: 2888 name: server - port: 3888 name: leader-election clusterIP: None selector: app: pre-zk --- apiVersion: v1 kind: Service metadata: name: pre-zk-cs namespace: pre labels: app: pre-zk spec: ports: - port: 2181 name: client selector: app: pre-zk --- apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: pre-zk-pdb namespace: pre spec: selector: matchLabels: app: pre-zk maxUnavailable: 1 --- apiVersion: apps/v1 kind: StatefulSet metadata: name: pre-zk namespace: pre spec: selector: matchLabels: app: pre-zk serviceName: pre-zk-hs replicas: 3 updateStrategy: type: RollingUpdate podManagementPolicy: OrderedReady template: metadata: labels: app: pre-zk spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/resource operator: In values: - pre-base podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: "app" operator: In values: - pre-zk topologyKey: "kubernetes.io/hostname" containers: - name: pre-zk imagePullPolicy: Always image: "k8s.gcr.io/kubernetes-zookeeper:1.0-3.4.10" resources: requests: memory: "1Gi" cpu: "0.5" limits: cpu: "1" memory: "1Gi" ports: - containerPort: 2181 name: client - containerPort: 2888 name: server - containerPort: 3888 name: leader-election command: - sh - -c - "start-zookeeper \ --servers=3 \ --data_dir=/var/lib/zookeeper/data \ --data_log_dir=/var/lib/zookeeper/data/log \ --conf_dir=/opt/zookeeper/conf \ --client_port=2181 \ --election_port=3888 \ --server_port=2888 \ --tick_time=2000 \ --init_limit=10 \ --sync_limit=5 \ --heap=512M \ --max_client_cnxns=60 \ --snap_retain_count=3 \ --purge_interval=12 \ --max_session_timeout=40000 \ --min_session_timeout=4000 \ --log_level=INFO" readinessProbe: exec: command: - sh - -c - "zookeeper-ready 2181" initialDelaySeconds: 10 timeoutSeconds: 5 livenessProbe: exec: command: - sh - -c - "zookeeper-ready 2181" initialDelaySeconds: 10 timeoutSeconds: 5 volumeMounts: - name: datadir mountPath: /var/lib/zookeeper # 如果是简单的测试sattefulSet安装zookeeper集群,使用临时存储即可 # StatefulSet 控制器为 StatefulSet 中的每个 Pod 生成一个 PersistentVolumeClaim #volumes: #- name: datadir # emptyDir: {} securityContext: runAsUser: 1000 fsGroup: 1000 # 正式环境,需要部署持久化存储 volumeClaimTemplates: - metadata: name: datadir annotations: volume.alpha.kubernetes.io/storage-class: anything spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 20Gi storageClassName: alicloud-disk-essd
这篇关于Kubernetes StatefulSet with zookeeper的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-05基于Kubernetes的自定义AWS云平台搭建指南
- 2024-11-05基于Kubernetes Gateway API的现代流量管理方案
- 2024-11-05在Kubernetes上部署你的第一个应用:Nginx服务器
- 2024-11-05利用拓扑感知路由控制Kubernetes中的流量
- 2024-11-05Kubernetes中的层次命名空间:更灵活的资源管理方案
- 2024-11-055分钟上手 Kubernetes:精简实用的 Kubectl 命令速查宝典!
- 2024-10-30K8s 容器的定向调度与亲和性
- 2024-10-28云原生周刊:K8s未来三大发展方向 丨2024.10.28
- 2024-10-25亚马逊弹性Kubernetes服务(EKS)实战:轻松搭建Kubernetes平台
- 2024-10-22KubeSphere 最佳实战:Kubernetes 部署集群模式 Nacos 实战指南