kubernetes 无法从minikube访问NodePort服务

qvtsj1bj  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(1)|浏览(576)

无法从minikube访问NodePort服务。我已尝试minikubeip+服务端口,但在尝试点击rest api时没有得到任何响应。我可以通过命令minikube service addressvalidationverone --url访问服务。
我部署文件:-
api版本:应用程序/v1种类:部署元数据:名称:地址验证verone规范:选择器:匹配标签:应用程序:地址验证verone复制副本:3.模板:元数据:标签:应用程序:地址验证verone规范:集装箱:- 名称:地址验证容器映像:地址验证每个映像拉取策略:如果不存在端口:- 集装箱港口:8080

my service yaml file
apiVersion: v1 
kind: Service 
metadata:
  name: addressvalidationverone 
spec:
  selector:
    app: addressvalidationverone
  ports:
    - protocol: "TCP"
      port: 8080 
      targetPort: 8080
  type: NodePort

This how the out put looks for 
kubectl describe service addressvalidaionverone

>kubectl describe service
Name:                     addressvalidationverone
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=addressvalidationverone
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.97.139.133
IPs:                      10.97.139.133
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30050/TCP
Endpoints:                172.17.0.5:8080,172.17.0.6:8080,172.17.0.7:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Can any body help on this. 

I have tried
>kubectl describe service
Name:                     addressvalidationverone
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=addressvalidationverone
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.97.139.133
IPs:                      10.97.139.133
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30050/TCP
Endpoints:                172.17.0.5:8080,172.17.0.6:8080,172.17.0.7:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
C:\Users\AbhayShitole\Documents\MasterDataManagement>minikube ip
192.168.49.2

I tried 192.168.49.2:30050/validate but there is no response in post man. it times out.
I am able to access the service through command minikube service addressvalidationverone --url.
o2gm4chl

o2gm4chl1#

似乎您遗漏了在yaml中添加NodePort。即使它应该被自动分配,service describe命令显示它没有设置。尝试添加spec.ports[*].nodePort,其端口介于30000-32767之间。请参阅文档以了解明确的配置:https://kubernetes.io/docs/concepts/services-networking/service/#nodeport-custom-port

相关问题