最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

etcd

互联网 admin 8浏览 0评论

etcd

1,k8s 中基础构建的静态配置清单

/etc/kubernetes/manifests

2,查看etcd 版本号

kubectl exec -it etcd-master -n kube-system  -- etcdctl version

kubectl  exec  etcd-master -n kube-system -- /bin/sh -c 'echo $PATH'
kubectl  exec  etcd-master -n kube-system -- /bin/sh -c 'etcdctl version'
kubectl  exec  etcd-master -n kube-system -- /bin/sh -c '/usr/local/bin/etcdctl version'
kubectl cp -n dev nginx-deployment-5b9bb9f548-8tl5t:usr/share/nginx/html/ ./html   #拷贝容器中的文件到宿主机上

3,查看容器架构

docker inspect k8s.gcr.io/ingress-nginx/controller:v1.2.0 |grep Architecture

4,kubeadm 安装下,etcd备份操作
蓝色
[root@master ~]# docker run -itd quay.io/coreos/etcd:v3.5.1-amd64 /bin/bash
52820fff1f401b2e9697d4b9873869e0e835588179b2e8bce7f3530749eb810b
[root@master ~]# docker ps |grep etcd
52820fff1f40 quay.io/coreos/etcd:v3.5.1-amd64 “/bin/bash” 5 seconds ago Up 5 seconds 2379-2380/tcp angry_shockley
8db7127cec4f 25f8c7f3da61 “etcd --advertise-cl…” About an hour ago Up About an hour k8s_etcd_etcd-master_kube-system_e8960f7e2ae8fbb220846f429f9f173c_0
34f2ca6814e9 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 “/pause” About an hour ago Up About an hour k8s_POD_etcd-master_kube-system_e8960f7e2ae8fbb220846f429f9f173c_0
[root@master ~]# docker exec 52820fff1f40 whereis etcdctl
etcdctl: /usr/local/bin/etcdctl
[root@master ~]# docker cp 52820fff1f40:/usr/local/bin/etcdctl ./etcdctl
[root@master ~]# ./etcdctl version
etcdctl version: 3.5.1
API version: 3.5

/usr/local/bin/etcdctl

4, etcd 数据库备份

ETCDCTL_API=3
./etcdctl --endpoints="https://127.0.0.1:2379"  \
--cert="/etc/kubernetes/pki/etcd/server.crt" \
--key="/etc/kubernetes/pki/etcd/server.key"   \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"  \
snapshot save /backup_$(date +%Y%m%d)/snap-$(date +%Y%m%d%H%M).db


mkdir /backup_KaTeX parse error: Expected group after '_' at position 60: …ot save /backup_̲(date +%Y%m%d)/snap-$(date +%Y%m%d%H%M).db

etcdctl endpoint status -w table # 查看etcd 数据库大小

5, 执行备份文件,恢复数据

  • 1,在恢复数据时,需要关停etcd、 apiserver
  • 2,再执行恢复语句
  • 3,启动etcd、apiserver 组件
    kubeadm 安装的k8s集群中,只需要简单修改下 静态pod资源清单即可 ——/etc/kubernetes/manifests/
    docker ps |grep -E ‘etcd|api’

    vim /etc/kubernetes/manifests/etcd.yaml # 修改etcd 版本号

    vim /etc/kubernetes/manifests/kube-apiserver.yaml #修改apiversion 版本号

再次查看etcd apiversion 发现containers 已停

[root@master ~]# docker ps |grep -E ‘etcd|api’

点单恢复数据:

./etcdctl --endpoints="https://127.0.0.1:2379" \
--cert="/etc/kubernetes/pki/etcd/server.crt"   \
--key="/etc/kubernetes/pki/etcd/server.key"   \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"  \
snapshot restore  /backup_20220605/snap-202206051053.db

etcdctl snapshot restore /backup_20220605/snap-202206051053.db --data-dir=/var/lib/etcd/

在执行etcd 数据恢复后,一般在命令执行的当前目录下会生成一个 default.etcd 文件


这个时候在恢复静态pod ,etcd、 apiversion 资源清单的版本号,熟悉的资源就又回来了
docker ps |grep -E ‘etcd|api’

官方文档
etcd 镜像下载源
etcd-华为二进制下载源
参考文档1
github

查看集群节点信息

./etcdctl --endpoints 127.0.0.1:2379 \
--cert="/etc/kubernetes/pki/etcd/server.crt"  \
--key="/etc/kubernetes/pki/etcd/server.key"  \
--cacert="/etc/kubernetes/pki/etcd/ca.crt" \
member list --write-out=table


etcdctl endpoint status -w table # 查看节点详情得

优化操作

添加一个别名,每次操作etcd时不需要指定很常的参数

alias etcdctl='/root/etcdctl --endpoints 127.0.0.1:2379 \
--cert="/etc/kubernetes/pki/etcd/server.crt"  \
--key="/etc/kubernetes/pki/etcd/server.key"  \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"'

别名永久化:
将alias 得命令 添加到文件~/.bashrc中 ,然后执行source 命令( source ~/.bashrc)即可。

etcdctl put key1 123 # 写入
etcdctl get key1 # 查询

写入目录格式得:

[root@master ~]# etcdctl put /henan/key1 value1
OK
[root@master ~]# etcdctl put /henan/key2 value2
OK
[root@master ~]# etcdctl put /henan/key3 value3
OK
[root@master ~]# etcdctl get /henan/ --prefix=true
/henan/key1
value1
/henan/key2
value2
/henan/key3
value3
[root@master ~]# 

etcdctl get / --prefix=true --keys-only #查看所有值
etcdctl get / --prefix=true --keys-only |wc -l #统计有多少个健
etcdctl get / --prefix=true --keys-only |grep pods # 查找集群中关于pod 得健
etcdctl get /registry/pods/dev/ --prefix=true --keys-only # 查看dev空间下得pod
etcdctl get /registry/pods/dev/nginx-deployment-5b9bb9f548-h9p4t --prefix=true # 查看dev空间下具体得pod信息

etcd

1,k8s 中基础构建的静态配置清单

/etc/kubernetes/manifests

2,查看etcd 版本号

kubectl exec -it etcd-master -n kube-system  -- etcdctl version

kubectl  exec  etcd-master -n kube-system -- /bin/sh -c 'echo $PATH'
kubectl  exec  etcd-master -n kube-system -- /bin/sh -c 'etcdctl version'
kubectl  exec  etcd-master -n kube-system -- /bin/sh -c '/usr/local/bin/etcdctl version'
kubectl cp -n dev nginx-deployment-5b9bb9f548-8tl5t:usr/share/nginx/html/ ./html   #拷贝容器中的文件到宿主机上

3,查看容器架构

docker inspect k8s.gcr.io/ingress-nginx/controller:v1.2.0 |grep Architecture

4,kubeadm 安装下,etcd备份操作
蓝色
[root@master ~]# docker run -itd quay.io/coreos/etcd:v3.5.1-amd64 /bin/bash
52820fff1f401b2e9697d4b9873869e0e835588179b2e8bce7f3530749eb810b
[root@master ~]# docker ps |grep etcd
52820fff1f40 quay.io/coreos/etcd:v3.5.1-amd64 “/bin/bash” 5 seconds ago Up 5 seconds 2379-2380/tcp angry_shockley
8db7127cec4f 25f8c7f3da61 “etcd --advertise-cl…” About an hour ago Up About an hour k8s_etcd_etcd-master_kube-system_e8960f7e2ae8fbb220846f429f9f173c_0
34f2ca6814e9 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 “/pause” About an hour ago Up About an hour k8s_POD_etcd-master_kube-system_e8960f7e2ae8fbb220846f429f9f173c_0
[root@master ~]# docker exec 52820fff1f40 whereis etcdctl
etcdctl: /usr/local/bin/etcdctl
[root@master ~]# docker cp 52820fff1f40:/usr/local/bin/etcdctl ./etcdctl
[root@master ~]# ./etcdctl version
etcdctl version: 3.5.1
API version: 3.5

/usr/local/bin/etcdctl

4, etcd 数据库备份

ETCDCTL_API=3
./etcdctl --endpoints="https://127.0.0.1:2379"  \
--cert="/etc/kubernetes/pki/etcd/server.crt" \
--key="/etc/kubernetes/pki/etcd/server.key"   \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"  \
snapshot save /backup_$(date +%Y%m%d)/snap-$(date +%Y%m%d%H%M).db


mkdir /backup_KaTeX parse error: Expected group after '_' at position 60: …ot save /backup_̲(date +%Y%m%d)/snap-$(date +%Y%m%d%H%M).db

etcdctl endpoint status -w table # 查看etcd 数据库大小

5, 执行备份文件,恢复数据

  • 1,在恢复数据时,需要关停etcd、 apiserver
  • 2,再执行恢复语句
  • 3,启动etcd、apiserver 组件
    kubeadm 安装的k8s集群中,只需要简单修改下 静态pod资源清单即可 ——/etc/kubernetes/manifests/
    docker ps |grep -E ‘etcd|api’

    vim /etc/kubernetes/manifests/etcd.yaml # 修改etcd 版本号

    vim /etc/kubernetes/manifests/kube-apiserver.yaml #修改apiversion 版本号

再次查看etcd apiversion 发现containers 已停

[root@master ~]# docker ps |grep -E ‘etcd|api’

点单恢复数据:

./etcdctl --endpoints="https://127.0.0.1:2379" \
--cert="/etc/kubernetes/pki/etcd/server.crt"   \
--key="/etc/kubernetes/pki/etcd/server.key"   \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"  \
snapshot restore  /backup_20220605/snap-202206051053.db

etcdctl snapshot restore /backup_20220605/snap-202206051053.db --data-dir=/var/lib/etcd/

在执行etcd 数据恢复后,一般在命令执行的当前目录下会生成一个 default.etcd 文件


这个时候在恢复静态pod ,etcd、 apiversion 资源清单的版本号,熟悉的资源就又回来了
docker ps |grep -E ‘etcd|api’

官方文档
etcd 镜像下载源
etcd-华为二进制下载源
参考文档1
github

查看集群节点信息

./etcdctl --endpoints 127.0.0.1:2379 \
--cert="/etc/kubernetes/pki/etcd/server.crt"  \
--key="/etc/kubernetes/pki/etcd/server.key"  \
--cacert="/etc/kubernetes/pki/etcd/ca.crt" \
member list --write-out=table


etcdctl endpoint status -w table # 查看节点详情得

优化操作

添加一个别名,每次操作etcd时不需要指定很常的参数

alias etcdctl='/root/etcdctl --endpoints 127.0.0.1:2379 \
--cert="/etc/kubernetes/pki/etcd/server.crt"  \
--key="/etc/kubernetes/pki/etcd/server.key"  \
--cacert="/etc/kubernetes/pki/etcd/ca.crt"'

别名永久化:
将alias 得命令 添加到文件~/.bashrc中 ,然后执行source 命令( source ~/.bashrc)即可。

etcdctl put key1 123 # 写入
etcdctl get key1 # 查询

写入目录格式得:

[root@master ~]# etcdctl put /henan/key1 value1
OK
[root@master ~]# etcdctl put /henan/key2 value2
OK
[root@master ~]# etcdctl put /henan/key3 value3
OK
[root@master ~]# etcdctl get /henan/ --prefix=true
/henan/key1
value1
/henan/key2
value2
/henan/key3
value3
[root@master ~]# 

etcdctl get / --prefix=true --keys-only #查看所有值
etcdctl get / --prefix=true --keys-only |wc -l #统计有多少个健
etcdctl get / --prefix=true --keys-only |grep pods # 查找集群中关于pod 得健
etcdctl get /registry/pods/dev/ --prefix=true --keys-only # 查看dev空间下得pod
etcdctl get /registry/pods/dev/nginx-deployment-5b9bb9f548-h9p4t --prefix=true # 查看dev空间下具体得pod信息

发布评论

评论列表 (0)

  1. 暂无评论