Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zoetrope committed Nov 24, 2019
1 parent 60182ec commit 4147fe9
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 77 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ start-etcd:
docker run --name etcd \
-p 2379:2379 \
--volume=etcd-data:/etcd-data \
--name etcd quay.io/coreos/etcd:v3.3.12 \
--name etcd gcr.io/etcd-development/etcd:v3.3.17 \
/usr/local/bin/etcd \
--name=etcd \
--name=etcd-1 \
--data-dir=/etcd-data \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-client-urls http://0.0.0.0:2379 \
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# etcd-book
# Go言語で学ぶetcdプログラミング

## PDFダウンロード

[https://github.com/zoetrope/etcd-book/releases](https://github.com/zoetrope/etcd-book/releases)

## PDFの生成方法

Expand Down
22 changes: 11 additions & 11 deletions articles/chapter1.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
今回はDockerを利用してetcdを起動するので、まずはDockerがインストールされていることを確認しましょう。

//cmd{
$ docker -v
Docker version 18.06.1-ce, build e68fc7a
$ docker -v
Docker version 19.03.5, build 633a0ea838
//}

次にetcdを起動します。
Expand All @@ -15,7 +15,7 @@ Docker version 18.06.1-ce, build e68fc7a
$ docker run --name etcd \
-p 2379:2379 \
--volume=etcd-data:/etcd-data \
--name etcd quay.io/coreos/etcd:v3.3.12 \
--name etcd gcr.io/etcd-development/etcd:v3.3.17 \
/usr/local/bin/etcd \
--name=etcd-1 \
--data-dir=/etcd-data \
Expand Down Expand Up @@ -43,14 +43,14 @@ etcdに以下の起動オプションを指定します。
//footnote[insecure][serving insecure client requests on [::\]:2379, this is strongly discouraged!というメッセージが表示されていますがここでは無視します。安全な接続方法については後ほど解説します。]

//terminal{
2019-03-03 03:53:34.908093 I | etcdmain: etcd Version: 3.3.12
2019-03-03 03:53:34.908213 I | etcdmain: Git SHA: GitNotFound
2019-03-03 03:53:34.908217 I | etcdmain: Go Version: go1.10.8
2019-03-03 03:53:34.908223 I | etcdmain: Go OS/Arch: linux/amd64
2019-11-24 05:29:22.996364 I | etcdmain: etcd Version: 3.3.17
2019-11-24 05:29:22.996423 I | etcdmain: Git SHA: 6d8052314
2019-11-24 05:29:22.996427 I | etcdmain: Go Version: go1.12.9
2019-11-24 05:29:22.996430 I | etcdmain: Go OS/Arch: linux/amd64
・・中略・・
2019-03-03 03:53:36.625034 I | etcdserver: published {Name:etcd-1 ClientURLs:[http://0.0.0.0:2379]} to cluster cdf818194e3a8c32
2019-03-03 03:53:36.625087 I | embed: ready to serve client requests
2019-03-03 03:53:36.625491 N | embed: serving insecure client requests on [::]:2379, this is strongly discouraged!
2019-11-24 05:29:24.603553 I | etcdserver: published {Name:etcd-1 ClientURLs:[http://0.0.0.0:2379]} to cluster cdf818194e3a8c32
2019-11-24 05:29:24.603602 I | embed: ready to serve client requests
2019-11-24 05:29:24.603989 N | embed: serving insecure client requests on [::]:2379, this is strongly discouraged!
//}

次にetcdctlを使います。etcdctlはetcdとやり取りするためのコマンドラインツールです。
Expand All @@ -66,7 +66,7 @@ USAGE:
etcdctl

VERSION:
3.3.12
3.3.17

API VERSION:
3.3
Expand Down
4 changes: 2 additions & 2 deletions articles/chapter2.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Goのバージョンを確認しておきましょうか。

//terminal{
$ go version
go version go1.12.1 linux/amd64
go version go1.13.4 linux/amd64
//}

本書ではGo 1.12.1を利用します
本書ではGo 1.13.4を利用します
本書のコードは多少古いGoでも動くとは思いますが、最新版を利用することをおすすめします。

ではetcdにアクセスするプログラムを書いてみましょう。
Expand Down
8 changes: 4 additions & 4 deletions articles/chapter4.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: '3'
services:
etcd1:
container_name: etcd1
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -28,7 +28,7 @@ services:
- --initial-cluster-state=new
etcd2:
container_name: etcd2
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -47,7 +47,7 @@ services:
- --initial-cluster-state=new
etcd3:
container_name: etcd3
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand Down Expand Up @@ -259,7 +259,7 @@ version: '3'
services:
etcd1:
container_name: etcd1
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
networks:
app_net:
ipv4_address: 172.30.0.11
Expand Down
37 changes: 18 additions & 19 deletions articles/chapter5.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

etcd-dump-logsは、etcdのコンテナイメージにも含まれていない。バイナリ配布もされていない。自前でビルドする必要がある。

```
//terminal{
$ git clone https://github.com/etcd-io/etcd.git
$ cd etcd
$ go install ./tools/etcd-dump-logs
```
//}

```
//terminal{
$ docker volume ls
DRIVER VOLUME NAME
local cluster_etcd1-data
local cluster_etcd2-data
local cluster_etcd3-data
```
//}

```
//terminal{
$ docker volume inspect cluster_etcd1-data
[
{
Expand All @@ -35,9 +35,9 @@ $ docker volume inspect cluster_etcd1-data
"Scope": "local"
}
]
```
//}

```
//terminal{
$ sudo etcd-dump-logs /var/lib/docker/volumes/cluster_etcd1-data/_data
Snapshot:
empty
Expand Down Expand Up @@ -66,29 +66,29 @@ term index type data
13 17 norm

Entry types () count is : 17
```
//}


```
//terminal{
/ # ETCDCTL_API=3 etcdctl --endpoints=etcd1:2379,etcd2:2379,etcd3:2379 endpoint status -w table
+------------+------------------+---------+---------+-----------+-----------+------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------+------------------+---------+---------+-----------+-----------+------------+
| etcd1:2379 | ade526d28b1f92f7 | 3.3.12 | 20 kB | false | 12 | 16 |
| etcd2:2379 | d282ac2ce600c1ce | 3.3.12 | 20 kB | true | 12 | 16 |
| etcd3:2379 | bd388e7810915853 | 3.3.12 | 20 kB | false | 12 | 16 |
| etcd1:2379 | ade526d28b1f92f7 | 3.3.17 | 20 kB | false | 12 | 16 |
| etcd2:2379 | d282ac2ce600c1ce | 3.3.17 | 20 kB | true | 12 | 16 |
| etcd3:2379 | bd388e7810915853 | 3.3.17 | 20 kB | false | 12 | 16 |
+------------+------------------+---------+---------+-----------+-----------+------------+
/ # ETCDCTL_API=3 etcdctl --endpoints=etcd1:2379,etcd2:2379,etcd3:2379 move-leader bd388e7810915853
Leadership transferred from d282ac2ce600c1ce to bd388e7810915853
/ # ETCDCTL_API=3 etcdctl --endpoints=etcd1:2379,etcd2:2379,etcd3:2379 endpoint status -w table
+------------+------------------+---------+---------+-----------+-----------+------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------+------------------+---------+---------+-----------+-----------+------------+
| etcd1:2379 | ade526d28b1f92f7 | 3.3.12 | 20 kB | false | 13 | 17 |
| etcd2:2379 | d282ac2ce600c1ce | 3.3.12 | 20 kB | false | 13 | 17 |
| etcd3:2379 | bd388e7810915853 | 3.3.12 | 20 kB | true | 13 | 17 |
| etcd1:2379 | ade526d28b1f92f7 | 3.3.17 | 20 kB | false | 13 | 17 |
| etcd2:2379 | d282ac2ce600c1ce | 3.3.17 | 20 kB | false | 13 | 17 |
| etcd3:2379 | bd388e7810915853 | 3.3.17 | 20 kB | true | 13 | 17 |
+------------+------------------+---------+---------+-----------+-----------+------------+
```
//}


== etcd operator
Expand Down Expand Up @@ -169,13 +169,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Prometheusにはサービスディスカバリを利用して、自動的にモニタリングの対象をみつける機能があります。
詳しくは以下参照。

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config

この機能を利用してetcdのメトリクスも収集してもらいましょう。
このとき、etcdのPodにアノテーションを付与する必要があります。

また、

//list[etcd-cluster][etcd-cluster.yml]{
#@mapfile(../code/chapter5/prometheus/etcd-cluster.yml)
apiVersion: "etcd.database.coreos.com/v1beta2"
Expand All @@ -184,7 +183,7 @@ metadata:
name: "example-etcd-cluster"
spec:
size: 3
version: "3.3.12"
version: "3.3.17"
pod:
annotations:
prometheus.io/scrape: 'true'
Expand Down
4 changes: 2 additions & 2 deletions articles/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ prt:
# a-trl, trl: 翻訳者

# 刊行日(省略した場合は実行時の日付)
date: 2019-04-14
#date: 2019-04-14
# 発行年月。YYYY-MM-DD形式による配列指定。省略した場合はdateを使用する
# 複数指定する場合は次のように記述する
# [["初版第1刷の日付", "初版第2刷の日付"], ["第2版第1刷の日付"]]
# 日付の後ろを空白文字で区切り、任意の文字列を置くことも可能。
history: [["2019-04-14 ver 1.0"]]
#history: [["2019-04-14 ver 1.0"]]
# [experimental] 新刊を頒布したイベント名(例:「技術書典6(2019年春)新刊」)
pubevent_name:
# 権利表記(配列で複数指定可)
Expand Down
2 changes: 1 addition & 1 deletion code/chapter3/isolation/isolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func fuzzyRead(client *clientv3.Client) {
v2 := stm.Get("/chapter3/iso/fuzzy")
if v1 != v2 {
// ReadCommittedが正しく実装されているならここでファジーリードが発生するはず。
// しかしetcd v3.3.12ではちゃんと実装されてない
// しかしetcd v3.3.17ではちゃんと実装されてない
fmt.Printf("fuzzy:%d, %s, %s\n", d, v1, v2)
}
stm.Put("/chapter3/iso/fuzzy", strconv.Itoa(value))
Expand Down
8 changes: 4 additions & 4 deletions code/chapter4/add_member/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
etcd1:
container_name: etcd1
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -21,7 +21,7 @@ services:
- --initial-cluster-state=new
etcd2:
container_name: etcd2
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -40,7 +40,7 @@ services:
- --initial-cluster-state=new
etcd3:
container_name: etcd3
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -59,7 +59,7 @@ services:
- --initial-cluster-state=new
etcd4:
container_name: etcd4
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand Down
6 changes: 3 additions & 3 deletions code/chapter4/cluster/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
etcd1:
container_name: etcd1
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -21,7 +21,7 @@ services:
- --initial-cluster-state=new
etcd2:
container_name: etcd2
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand All @@ -40,7 +40,7 @@ services:
- --initial-cluster-state=new
etcd3:
container_name: etcd3
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
ports:
- 2379
- 2380
Expand Down
6 changes: 3 additions & 3 deletions code/chapter4/tls/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
etcd1:
container_name: etcd1
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
networks:
app_net:
ipv4_address: 172.30.0.11
Expand Down Expand Up @@ -35,7 +35,7 @@ services:
#@range_end(etcd1)
etcd2:
container_name: etcd2
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
networks:
app_net:
ipv4_address: 172.30.0.12
Expand Down Expand Up @@ -66,7 +66,7 @@ services:
- --peer-trusted-ca-file=/certs/ca.pem
etcd3:
container_name: etcd3
image: quay.io/coreos/etcd:v3.3.12
image: gcr.io/etcd-development/etcd:v3.3.17
networks:
app_net:
ipv4_address: 172.30.0.13
Expand Down
2 changes: 1 addition & 1 deletion code/chapter5/prometheus/etcd-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: "example-etcd-cluster"
spec:
size: 3
version: "3.3.12"
version: "3.3.17"
pod:
annotations:
prometheus.io/scrape: 'true'
Expand Down
Loading

0 comments on commit 4147fe9

Please sign in to comment.