k8s部署单节点etcd

需求nfs持久卷

 pv.yaml

# 数据存储卷
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: etcd-pv
  namespace: etcd
spec:
  capacity:
    storage: 2Gi   # 和etcd容器匹配
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: etcd-pv   # 持久卷匹配
  nfs:
    path: /data/ew/nfs/etcd_chat/pv1   # 持久卷地址
    server: 172.xx.xx.xx   # 持久卷服务器地址

etcd.yaml

# service-headless
---
apiVersion: v1
kind: Service
metadata:
  name: etcd-headless
  labels:
    app: etcd
spec:
  ports:
  - port: 2380
    name: etcd-server
  - port: 2379
    name: etcd-client
  clusterIP: None
  selector:
    app: etcd
  publishNotReadyAddresses: true

# service
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: etcd
  name: etcd-svc
spec:
  ports:
  - name: etcd-cluster
    port: 2379
    targetPort: 2379
    nodePort: 30109   # nodePort
  selector:
    app: etcd
  sessionAffinity: None
  type: NodePort

# etcd容器
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: etcd
  name: etcd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: etcd
  serviceName: etcd-headless
  template:
    metadata:
      labels:
        app: etcd
      name: etcd
    spec:
      containers:
        - env:
          - name: MY_POD_NAME  #当前pod名
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: CLUSTER_NAMESPACE  #名称空间
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: SERVICE_NAME   #内部通信的无头服务名称
            value: "etcd-headless"
          - name: INITIAL_CLUSTER   #initial-cluster的值
            value: "etcd-0=http://etcd-0.etcd-headless:2380"
          image: registry.cn-hangzhou.aliyuncs.com/leige24/k8s-etcd:v1
          imagePullPolicy: IfNotPresent
          name: etcd
          ports:
          - containerPort: 2380
            name: peer
            protocol: TCP
          - containerPort: 2379
            name: client
            protocol: TCP
          volumeMounts:
          - mountPath: /var/lib/etcd
            name: data-etcd
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      name: data-etcd
    spec:
      accessModes: ["ReadWriteOnce"]
      volumeMode: Filesystem
      resources:
        requests:
          storage: 2Gi   # 和nfs pv匹配
      storageClassName: etcd-pv   # 上面做的持久卷storageClassName

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值