2017-08-05 61 views
2

我试图揭露我的API,所以我可以发送请求给它。然而,当我用命令minikube service api --url我什么也没得到。我所有的舱体根据kubectl get pods运行良好,所以我升技卡住什么,这可能是。minikube服务SERVICENAME%%--url返回任何

api-1007925651-0rt1n  1/1  Running 0   26m 
auth-1671920045-0f85w  1/1  Running 0   26m 
blankit-app    1/1  Running 5   5d 
logging-2525807854-2gfwz 1/1  Running 0   26m 
mongo-1361605738-0fdq4  1/1  Running 0   26m 


jwl:.build jakewlace$ kubectl get services 

NAME   CLUSTER-IP EXTERNAL-IP PORT(S)  AGE 
api   10.0.0.194 <none>  3001/TCP 23m 
auth   10.0.0.36 <none>  3100/TCP 23m 
kubernetes 10.0.0.1  <none>  443/TCP  5d 
logging  10.0.0.118 <none>  3200/TCP 23m 
mongo  10.0.0.132 <none>  27017/TCP 23m 

jwl:.build jakewlace$ 
jwl:.build jakewlace$ minikube service api --url 
jwl:.build jakewlace$ 

任何帮助将大规模赞赏,谢谢。

我意识到这里的问题可能会被视为是最小的,但那是因为我不知道是什么的详细信息,我可以从我一直在关注它应该只是工作教程显示。如果你需要更多的信息,请让我知道我会让你知道。

编辑:

API-service.yml

apiVersion: v1 
kind: Service 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: api 
    name: api 
spec: 
    ports: 
    - name: "3001" 
    port: 3001 
    targetPort: 3001 
    selector: 
    io.kompose.service: api 
status: 
    loadBalancer: {} 

API-deployment.yml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    creationTimestamp: null 
    labels: 
    io.kompose.service: api 
    name: api 
spec: 
    replicas: 1 
    strategy: {} 
    template: 
    metadata: 
     creationTimestamp: null 
     labels: 
     io.kompose.service: api 
    spec: 
     containers: 
     - image: blankit/web:0.0.1 
     name: api 
     imagePullPolicy: IfNotPresent 
     ports: 
     - containerPort: 3001 
     resources: {} 
     restartPolicy: Always 
status: {} 
+0

你能分享你的 'API' 服务YAML文件? –

+0

@DavidB。我已经添加了配置。 –

回答

3

你的配置是不错,但唯一缺少的一两件事。

有许多类型的Kubernetes Services,但在这种情况下,你应该知道其中的两个命令:

ClusterIP服务:
暴露了美国在集群内部的IP服务。选择此值使得该服务只能从群集内访问。这是默认设置。

NodePort:
在静态端口(NodePort)自曝在每个节点上的IP服务。一个ClusterIP服务,该服务NodePort意志路线,自动创建。您可以联系NodePort服务,从集群外,通过请求<NodeIP>:<NodePort>

注:
如果你有一个多节点集群,你已经露出了NodePort服务,您可以访问来自同一个端口上的其他节点,不一定是相同的节点荚被部署到。

于是,又回到了你的服务,你应该在你的规范指定服务类型:

kind: Service 
apiVersion: v1 
metadata: 
    ... 
spec: 
    type: NodePort 
    selector: 
    ... 
    ports: 
    - protocol: TCP 
    port: 3001 

现在,如果你minikube service api --url,它应该返回一个URL像http://<NodeIP>:<NodePort>

注意:默认的Kubernetes配置将从30000-32767中选择一个随机端口。但是如果需要的话,你可以覆盖它。


有用的参考资料:

+0

很棒,你是对的。谢谢你回复 –

+0

@JakeLacey,很高兴帮助:) –