Che Chia Chang https://chechia.net/
https://www.cake.me/companies/maicoin/jobs
git clone https://github.com/chechiachang/etcd-playground.git
workshop 提供的機器
VERSION=v4.44.3
BINARY=yq_darwin_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O yq
chmod +x yq
sudo mv yq /usr/bin/yq
一行一行執行底下指令,來啟動一台 etcd
cd etcd-playground
ls
cd 00-prerequsites/
cat docker-compose.yaml
docker compose up -d
docker ps
docker logs -f etcd-0
卡住時 ctrl + c to exit
只領打一半可以按 tab auto complete
https://etcd.io/docs/v3.5/tutorials/ 中的幾個範例
etcdctl get foo
etcdctl put foo "Hello World"
etcdctl get foo
https://etcd.io/docs/v3.5/tutorials/ 中的幾個範例
etcdctl get --prefix ""
etcdctl get "" --prefix --keys-only
etcdctl put foo2 2
etcdctl put foo5 5
etcdctl put foo4 4
etcdctl put foo3 3
etcdctl get foo --prefix --keys-only
etcdctl get foo --prefix --keys-only --sort-by=KEY --limit=5
etcdctl get foo --prefix --keys-only --sort-by=MODIFY --limit=5
請嘗試操作 https://etcd.io/docs/v3.5/tutorials/ 中的幾個範例
etcdctl del foo
etcdctl put k1 value1
etcdctl put k2 value2
etcdctl del --prefix k
透過以下 command 重啟 etcd
docker ps
確認 etcd 是否還在運行docker ps
docker compose down
docker ps
docker compose up -d
etcdctl put foo bar
docker compose down
docker compose up -d
etcdctl get foo
cd 00-prerequsites/
sudo ls etcd0
sudo ls etcd0/member
docker compose down --volumes
sudo rm -rf etcd0/*
# 新的 etcd
docker compose up -d
ls etcd0
啟用 etcd 的 authentication
docker compose down --volumes
sudo rm -rf etcd0/*
# 可能會用到的 cmd
etcdctl role add
etcdctl role grant-permission
etcdctl user add
etcdctl user list
etcdctl auth status
etcdctl auth enable
--volumes
刪除 docker volumedocker compose down --volumes
sudo rm -rf etcd0/*
cd ../
cd 01-cluster/
cat docker-compose.yaml
docker compose up -d
docker ps
etcdctl endpoint status
etcdctl --endpoints "http://127.0.0.1:2379,http://127.0.0.1:2380" endpoint status
etcdctl --endpoints "http://127.0.0.1:2379,http://127.0.0.1:2380,http://127.0.0.1:2381" endpoint status
export ETCDCTL_ENDPOINTS="http://127.0.0.1:2379,http://127.0.0.1:2380,http://127.0.0.1:2381"
etcdctl --endpoints $ETCDCTL_ENDPOINTS endpoint status
etcdctl endpoint status
https://etcd.io/docs/v3.5/tutorials/
--help
檢查每個欄位的意義etcdctl endpoint status
etcdctl endpoint status --help
etcdctl endpoint health
etcdctl endpoint health --help
etcdctl endpoint hashkv
etcdctl endpoint hashkv --help
move-leader
指令,可以交接 leaderetcdctl --write-out=table endpoint status
docker exec -it etcd-1 etcdctl move-leader 88d11e2649dad027
etcdctl --write-out=table endpoint status
https://etcd.io/docs/v3.5/tutorials/
etcdctl member remove
etcdctl member remove c3697a4fd7a20dcd
etcdctl member list
etcdctl member add c3697a4fd7a20dcd --peer-urls="http://etcd-3:2380"
etcdctl member list
sudo rm -rf etcd3/member
docker start etcd-3
etcdctl member list
啟用 etcd cluster 的 tls,並讓 etcdcetl 透過 tls 連線
etcdctl member list
docker ps -a
etcdctl get "" --prefix --keys-only
cd 02-control-panel
cd certs
./generate.sh
cd ../
cat docker-compose.yaml
docker compose up -d
docker ps
docker logs kube-apiserver
docker logs kube-controller-manager
docker logs kube-scheduler
https://kubernetes.io/docs/concepts/overview/components/
etcdctl get "" --prefix --keys-only
kubectl --kubeconfig=certs/admin.kubeconfig cluster-info
kubectl --kubeconfig=certs/admin.kubeconfig get all -A
/registry
的 key,探索更多 k8s 內容etcdctl get "/" --prefix --keys-only --sort-by=KEY
etcdctl get /registry/namespaces/default -w json | jq
etcdctl get /registry/namespaces/default -w json | yq -P
k8s 運行時,會將資料存放在 etcd 中
etcdctl get "/registry/namespaces" --prefix --keys-only --sort-by=KEY
kubectl --kubeconfig=certs/admin.kubeconfig create namespace workshop
etcdctl get /registry/namespaces/workshop -w json | yq -P
kelseyhightower/kubernetes-the-hard-way 是一個很棒的學習資源,可以讓你了解到 Kubernetes 的每個細節
certs/generate.sh 有附上對應的 k8s-the-hard-way 的說明文件
vi certs/generate.sh
ls certs
ls apiserver
ls controller-manager
ls scheduler
k8s 官方文件中,從維運 k8s 角度,講述如何維運 etcd
etcdctl --write-out=table endpoint status
docker exec -it etcd-1 etcdctl snapshot save /etcd_data/snapshot.db
ls etcd1
docker stop kube-apiserver
cp etcd1/snapshot.db etcd2/snapshot.db
cp etcd1/snapshot.db etcd3/snapshot.db
docker exec -it etcd-1 etcdctl snapshot restore /etcd_data/snapshot.db
docker exec -it etcd-2 etcdctl snapshot restore /etcd_data/snapshot.db
docker exec -it etcd-3 etcdctl snapshot restore /etcd_data/snapshot.db
etcdctl --write-out=table endpoint status
# 可能會用到的 cmd
etcdctl member list
etcdctl member add <id> --peer-urls=
etcdctl member list
docker compose up -d