Minikube无法使用yaml公开服务

时间:2017-11-15 03:54:22

标签: kubernetes minikube

尝试运行本地注册表。我有以下配置:

部署:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: registry
  labels:
    app: registry
    role: registry
spec:
  replicas: 1
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
    spec:
      containers:
      - name: registry
        image: registry:latest
        ports:
        - containerPort: 5000
        volumeMounts:
          - mountPath: '/registry'
            name: registry-volume
      volumes:
      - name: registry-volume
        hostPath:
          path: '/data'
          type: Directory

服务:

apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
spec:
  selector:
    role: registry
  type: NodePort
  ports:
    - name: registry
      nodePort: 31001
      port: 5000
      protocol: TCP

创建部署/服务时一切正常。 kubectl显示服务和部署的状态为Running

NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/registry   1         1         1            1           30m

NAME                     DESIRED   CURRENT   READY     AGE
rs/registry-6549cbc974   1         1         1         30m

NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/registry   1         1         1            1           30m

NAME                     DESIRED   CURRENT   READY     AGE
rs/registry-6549cbc974   1         1         1         30m

NAME                           READY     STATUS    RESTARTS   AGE
po/registry-6549cbc974-mmqpj   1/1       Running   0          30m

NAME             TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
svc/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP          37m
svc/registry     NodePort    10.0.0.6     <none>        5000:31001/TCP   7m

但是,当我尝试使用minikube service registry --url获取服务的外部IP时,它会超时/失败:Waiting, endpoint for service is not ready yet...

当我删除服务(保持部署完好无损),并使用kubectl expose deployment registry --type=NodePort手动公开部署时,我能够使其正常工作。

可以找到Minikube日志here

1 个答案:

答案 0 :(得分:1)

您需要在spec.selector服务清单中指定正确的registry

apiVersion: v1
kind: Service
metadata:
  name: registry
  namespace: default
  labels:
    app: registry
spec:
  selector:
    app: registry
  type: NodePort
  ports:
    - name: registry
      nodePort: 31001
      port: 5000
      protocol: TCP

现在registry服务正确指向registry广告连播:

$ kubectl get endpoints
NAME         ENDPOINTS         AGE
kubernetes   10.0.2.15:8443    14m
registry     172.17.0.4:5000   4s

你也可以获得外部网址:

$ minikube service registry --url
http://192.168.99.106:31001