{"level":"warn","ts":"2019-04-12T09:35:08.363+0800","caller":"clientv3/retry_interceptor.go:60","msg":"retrying of unary invoker failed","target":"endpoint://client-75011900-151b-4d72-995e-2ece8279c305/loca
lhost:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = context deadline exceeded"}
put failed, err: context deadline exceeded
调用etcdv3时 出错 ,怎么解决?
请检查下etcd的版本;如果是docker,默认镜像好像是v2,用etcdctl看看。
使用git clone项目,然后自己docker build的镜像是最新的。
我的docker启动命令,使用自己build的镜像,和go代码例子。
docker run -d --restart=always -p 2379:2379 -p 2380:2380 -v /data/docker/etcd/node1:/node1.etcd -e ETCD_NAME=node1 -e ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379 -e ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 etcd
```golang
package main
import (
"log"
"time"
"context"
"github.com/coreos/etcd/client"
)
func main() {
cfg := client.Config{
Endpoints: []string{"http://127.0.0.1:2379"},
Transport: client.DefaultTransport,
// set timeout per request to fail fast when the target endpoint is unavailable
HeaderTimeoutPerRequest: time.Second,
}
c, err := client.New(cfg)
if err != nil {
log.Fatal(err)
}
kapi := client.NewKeysAPI(c)
// set "/foo" key with "bar" value
log.Print("Setting '/foo' key with 'bar' value")
resp, err := kapi.Set(context.Background(), "/foo", "bar", nil)
if err != nil {
log.Fatal(err)
} else {
// print common key info
log.Printf("Set is done. Metadata is %q\n", resp)
}
// get "/foo" key's value
log.Print("Getting '/foo' key value")
resp, err = kapi.Get(context.Background(), "/foo", nil)
if err != nil {
log.Fatal(err)
} else {
// print common key info
log.Printf("Get is done. Metadata is %q\n", resp)
// print value
log.Printf("%q key has %q value\n", resp.Node.Key, resp.Node.Value)
}
}
```
#2