etcd 查看所有key_《蹲坑学kubernetes》之8-4:Etcd操作使用
本节主要学习Etcd的操作使用图1:Kubernetes之Log1、查看帮助[root@k8s-master ~]# etcdctl --help图2:Etcd的帮助2、set设置某个键的值格式:etcdctl set--ttl '0': 设置该键值的超时时间(秒),不配置(默认0)则永不超时 例如:[root@k8s-master ~]# etcdctl --ca-file=/usr/loc..
·
本节主要学习Etcd的操作使用
1、查看帮助
[root@k8s-master ~]# etcdctl --help
2、set
设置某个键的值
格式:etcdctl set
--ttl '0': 设置该键值的超时时间(秒),不配置(默认0)则永不超时
例如:
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 set /data/key1 "hello world"
3、get
获取指定键的值
格式:etcdctl get
例如:
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 get /data/key1
由于是Etcd群集,在其他节点也能获取指定键的值
例如:
[root@k8s-node-1 ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 get /data/key1
4、update
当键存在的时候,更新值(不存在的时候会报错)
格式:etcdctl update
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 update /data/key1 "python java"[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 get /data/key1
5、rm
删除某个键值
格式:etcdctl rm
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 rm /data/key1
6、mk
创建一个新的键值
格式:etcdctl mk
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 mk /data/key1 "hello world"
7、操作目录
mkdir:如果给定的键目录不存在,则创建一个新的键目录
setdir:创建一个键目录
updatedir:更新一个已经存在的目录
rmdir:删除一个空目录
ls:列出目录(默认是跟目录)下的键或者子目录
例如:
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 mkdir /backup[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 mkdir /bakcup/a[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 mkdir /bakcup/b[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 mkdir /bakcup/c [root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 ls /bakcup/
8、backup
(1)备份etcd数据
1、--data-dir: etcd的数据目录
2、--backup-dir: 备份到指定路径
[root@k8s-master ~]# etcdctl --ca-file=/usr/local/kubernetes/ssl/ca.pem --cert-file=/usr/local/kubernetes/ssl/etcd.pem --key-file=/usr/local/kubernetes/ssl/etcd-key.pem --endpoints=https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 backup --data-dir=/var/lib/etcd/default.etcd --backup-dir=/backup/default.bak
查看备份:
(2)使用备份数据启动etcd
[root@k8s-master ~]# etcd --data-dir=/backup/default.bak --force-new-cluster
更多推荐
已为社区贡献1条内容
所有评论(0)