Kubernetes 1.20.15 单点部署 etcd v3.5.0:指定挂载目录、优化性能
Kubernetes 1.20.15 单点部署 etcd v3.5.0:指定挂载目录、优化性能
本文介绍如何在 Kubernetes 1.20.15 中使用 Deployment 部署单点 etcd v3.5.0 实例,并提供完整的 YAML 代码示例。
部署 etcd v3.5.0 的 YAML 代码
apiVersion: apps/v1
kind: Deployment
metadata:
name: etcd
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: etcd
template:
metadata:
labels:
app: etcd
spec:
containers:
- name: etcd
image: quay.io/coreos/etcd:v3.5.0
command:
- /usr/local/bin/etcd
args:
- '--name=etcd-0'
- '--data-dir=/var/lib/etcd'
- '--listen-client-urls=http://0.0.0.0:2379'
- '--advertise-client-urls=http://0.0.0.0:2379'
- '--listen-peer-urls=http://0.0.0.0:2380'
- '--initial-advertise-peer-urls=http://0.0.0.0:2380'
- '--initial-cluster=etcd-0=http://0.0.0.0:2380'
- '--initial-cluster-token=etcd-cluster-1'
- '--initial-cluster-state=new'
- '--auto-compaction-retention=1'
- '--heartbeat-interval=100'
- '--election-timeout=500'
- '--auto-tls=false'
- '--peer-auto-tls=false'
- '--client-cert-auth=false'
- '--peer-client-cert-auth=false'
volumeMounts:
- name: etcd-data
mountPath: /var/lib/etcd
volumes:
- name: etcd-data
hostPath:
path: /data/etcd
type: DirectoryOrCreate
配置解释
replicas: 1:表示只部署一个 etcd 实例,实现单点部署。--name=etcd-0和--initial-cluster=etcd-0=http://0.0.0.0:2380:将 etcd 实例命名为 etcd-0,并将其作为集群的唯一成员。--data-dir=/var/lib/etcd、volumeMounts和volumes:将 etcd 数据目录挂载到容器的/var/lib/etcd路径,使用 hostPath 将宿主机的/data/etcd目录挂载到容器的/var/lib/etcd路径,实现 etcd 数据持久化。--auto-compaction-retention=1:开启自动压缩,保留最近 1 个小时内的数据。--heartbeat-interval=100和--election-timeout=500:设置心跳间隔为 100 毫秒,选举超时时间为 500 毫秒,优化 etcd 性能。
注意事项
- 上面的配置只适用于单点部署。如果需要部署多个 etcd 实例,需要进行其他配置。
- 请确保宿主机的
/data/etcd目录存在,并具有相应的权限。
原文地址: https://www.cveoy.top/t/topic/nlFx 著作权归作者所有。请勿转载和采集!