Etcd具備下面這些屬性:算法
自從2014年成爲Kubernetes的一部分以來,Etcd社區呈現指數級的增加。CoreOS、谷歌、Redhat、IBM、思科、華爲等等均是Etcd的貢獻成員。其中AWS、谷歌雲平臺和Azure等大型雲提供商成功在生產環境中使用了Etcd。安全
Etcd在Kubernetes中的工做是爲分佈式系統安全存儲關鍵數據。它最著名的是Kubernetes的主數據存儲,用於存儲配置數據、狀態和元數據。因爲Kubernetes一般運行在幾臺機器的集羣上,所以它是一個分佈式系統,須要Etcd這樣的分佈式數據存儲。內網部署同一網段狀況下訪問很方便。網絡
但當集羣基於雲部署的時候客戶端多要跨網絡訪問集羣。今天,咱們會專門爲你們介紹兩個跨網絡訪問方案:ssh
方案一:每一個Etcd節點擁有公網ip,經過指定--advertise-client-urls 參數經過公網IP廣播地址curl
方案二:Etcd節點無公網ip,經過網關及ssh tunnel轉發請求分佈式
具體實施可參考如下步驟:url
如須要經過internet訪問Etcd集羣,必須配置 --advertise-client-urls 爲內網ip和外網IP例如:spa
--advertise-client-urls http://10.0.64.100:2379,http://125.94.39.48:2380
./etcd --name etcd0 --initial-advertise-peer-urls http://10.0.64.100:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://10.0.64.100:2379,http://125.94.39.48:2380 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 & ./etcd --name etcd1 --initial-advertise-peer-urls http://10.0.64.101:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://10.0.64.101:2379,http://125.94.39.105:2380 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 & ./etcd --name etcd2 --initial-advertise-peer-urls http://10.0.64.102:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://10.0.64.102:2379,http://59.37.136.50:2380 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 &
export ETCDCTL_API=3 #內網訪問 etcdctl --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379 member list #公網訪問 etcdctl --endpoints=http://125.94.39.48:2379,http://125.94.39.105:2379,http://59.37.136.50:2379 member list curl http://125.94.39.48:2379/v2/keys/message
經過網關訪問集羣,集羣無公網IP,gateway有公網IP。code
luster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 & ./etcd --name etcd1 --initial-advertise-peer-urls http://10.0.64.101:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://10.0.64.101:2379 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 & ./etcd --name etcd2 --initial-advertise-peer-urls http://10.0.64.102:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --listen-client-urls http://0.0.0.0:2379 \ --advertise-client-urls http://10.0.64.102:2379 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \ --initial-cluster-state new >> etcd.log 2>&1 &
etcd gateway start --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379 >> etcd_gateway.log 2>&1 &
export ETCDCTL_API=3 etcdctl --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379 member list etcdctl --endpoints=http://127.0.0.1:23790 member list
# 有公網ip地址主機上執行 ssh -g -f -N -L 23690:127.0.0.1:23790 root@127.0.0.1
export ETCDCTL_API=3 etcdctl --endpoints=http://157.255.51.197:23690 member list etcdctl --endpoints=http://157.255.51.197:23690 put foo bar etcdctl --endpoints=http://157.255.51.197:23690 get foo
歡迎點擊「京東雲」瞭解更多精彩blog