【发布时间】:2020-04-29 11:28:52
【问题描述】:
kubernetes 版本:1.5.2
操作系统:centos 7
etcd 版本:3.4.0
首先,我创建一个 etcd pod、etcd dockerfile 和 etcd pod YAML 文件,如下所示:
etcd dockerfile:
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,我运行命令useETCDCTL_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。
怎么了?如何使服务有用?
【问题讨论】:
标签: kubernetes kubernetes-pod kubernetes-service