1. 启动服务

Kubernetes 集群中,kubelet 作为节点的 Agent 可以通过监听 staticPodPath 方式监听一个目录中资源文件。

staticPodPath: /etc/kubernetes/manifests

可以将 Pod 的资源文件移动到 /etc/kubernetes/manifests/ 目录,kubelet 会自动检测到该配置并启动服务。

etcd 的 Static Pod 资源文件内容

$ cat /etc/kubernetes/manifests/my-etcd.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    component: my-etcd
  name: my-etcd
  namespace: kube-system
spec:
  containers:
  - command:
    - /usr/local/bin/etcd
    - --advertise-client-urls=http://10.100.0.13:42379
    - --auto-compaction-mode=periodic
    - --auto-compaction-retention=1h
    - --client-cert-auth=false
    - --data-dir=/data/my-etcd
    - --initial-advertise-peer-urls=http://10.100.0.13:42380
    - --initial-cluster-token=my-etcd
    - --listen-client-urls=http://10.100.0.13:42379,http://127.0.0.1:42379
    - --listen-peer-urls=http://10.100.0.13:42380
    - --logger=zap
    - --log-outputs=stderr,/var/log/etcd/my-etcd.log
    - --name=etcd01
    - --peer-client-cert-auth=false
    - --snapshot-count=10000
    image: registry.cn-hangzhou.aliyuncs.com/cncfstack/mywiki-etcd:v1-20201229
    imagePullPolicy: IfNotPresent
    env:
    - name: ETCD_INITIAL_CLUSTER
      value: "etcd01=http://10.100.0.13:42380"
    - name: ETCD_INITIAL_CLUSTER_STATE
      value: new
    livenessProbe:
      exec:
        command:
        - /bin/sh
        - -ec
        - ETCDCTL_API=3 etcdctl --endpoints=http://[127.0.0.1]:42379 get foo
      failureThreshold: 8
      initialDelaySeconds: 15
      timeoutSeconds: 15
    name: my-etcd
    resources:
      limits:
        cpu: "1"
        memory: "2G"
    volumeMounts:
    - mountPath: /data/my-etcd
      name: etcd-data
    - mountPath: /etc/localtime
      name: localtime
    - mountPath: /var/log/etcd
      name: etcd-log
  hostNetwork: true
  volumes:
  - hostPath:
      path: /data/my-etcd/data
      type: DirectoryOrCreate
    name: etcd-data
  - hostPath:
      path: /etc/localtime
    name: localtime
  - hostPath:
      path: /data/my-etcd/log
    name: etcd-log

查看容器运行状态

$  kubectl  -n kube-system get pod  -o wide |grep -iE "NAME|my-etcd"
NAME                                              READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
my-etcd-10.100.0.13                               1/1     Running   0          5m14s   10.100.0.13    10.100.0.13   <none>           <none>

查看 etcd 集群状态

$ /tmp/etcdctl --endpoints http://127.0.0.1:42379 endpoint status -w table
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|        ENDPOINT        |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://127.0.0.1:42379 | 50e57ef7cc044ac4 |  3.4.14 |   20 kB |      true |      false |         2 |          5 |                  5 |        |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

读写数据

$ /tmp/etcdctl --endpoints http://127.0.0.1:42379 put testkey testvalue
OK
$ /tmp/etcdctl --endpoints http://127.0.0.1:42379 get testkey
testkey
testvalue
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-10-26 17:23:11

results matching ""

    No results matching ""