kubernetes版本:1.5.2
操作系统:centos 7
etcd版本:3.4.0

首先,我创建一个etcd pod,etcd dockerfile和etcd pod YAML文件,如下所示:
etcd docker文件:

FROM alpine

COPY . /usr/bin
WORKDIR /usr/bin

CMD etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379

EXPOSE 2379

pod Yaml文件

apiVersion: v1
kind: Pod
metadata:
  name: etcd
  namespace: storageplatform
  labels:
    app: etcd
spec:
  containers:
    - name: etcd
      image: "karldoenitz/etcd:3.4.0"
      ports:
        - containerPort: 2379
          hostPort: 12379

创建docker镜像并推送到dockerhub之后,我运行命令kubectl apply -f etcd.yaml创建etcd pod。
etcd pod的ip是10.254.140.117,我使用ETCDCTL_API=3 etcdctl --endpoints=175.24.47.64:12379 put 1 1运行了命令,得到了OK
我的服务Yaml:

apiVersion: v1
kind: Service
metadata:
  name: storageservice
  namespace: storageplatform
spec:
  type: NodePort
  ports:
    - port: 12379
      targetPort: 12379
      nodePort: 32379
  selector:
    app: etcd

应用yaml文件创建服务。运行命令kubectl get services -n storageplatform,我得到了这些信息。
NAMESPACE         NAME                   CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
storageplatform   storageservice         10.254.140.117   <nodes>       12379:32379/TCP   51s

毕竟,我运行命令

ETCDCTL_API=3 etcdctl --endpoints=10.254.140.117:32379 get 1

要么

ETCDCTL_API=3 etcdctl --endpoints={host-ip}:32379 get 1

我得到了Error: context deadline exceeded

怎么了?如何使服务有用?

最佳答案

更改服务以引用containerPort而不是hostPort

apiVersion: v1
kind: Service
metadata:
  name: storageservice
  namespace: storageplatform
spec:
  type: NodePort
  ports:
    - port: 2379
      targetPort: 2379
      nodePort: 32379
  selector:
    app: etcd

关于kubernetes - 调用Kubernetes服务失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61500755/

10-15 20:02