我是kubernetes的新手,无法解决此问题。 服务和pod正在运行,但我无法从邮递员那里得到回复。
kubectl获取服务
kubectl获得服务人员服务-o json
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"annotations": {
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"personservice\"},\"name\":\"personservice\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"nodePort\":30001,\"port\":8080,\"protocol\":\"TCP\"}],\"selector\":{\"app\":\"personservice\"},\"type\":\"NodePort\"}}\n"
},
"creationTimestamp": "2019-11-07T11:22:04Z",
"labels": {
"app": "personservice"
},
"name": "personservice",
"namespace": "default",
"resourceVersion": "84920",
"selfLink": "/api/v1/namespaces/default/services/personservice",
"uid": "d32d4dd8-0150-11ea-80e6-00155d010311"
},
"spec": {
"clusterIP": "10.98.168.74",
"externalTrafficPolicy": "Cluster",
"ports": [
{
"nodePort": 30001,
"port": 8080,
"protocol": "TCP",
"targetPort": 8080
}
],
"selector": {
"app": "personservice"
},
"sessionAffinity": "None",
"type": "NodePort"
},
"status": {
"loadBalancer": {}
}
}
kubectl获取广告连播
当我尝试使用邮递员打它
http://100.120.60.210:30001/getPerson?nino=12345Ac&id=1
我得到“连接到http://100.120.60.210:30001/getPerson?nino=12345Ac&id=1时出错。”
IPv4 Address. . . . . . . . . . . : 100.120.60.210 --- Ip address of my laptop.
修改1: pod部署配置:
apiVersion: apps/v1
kind: Deployment
metadata:
name: personservice
labels:
app: personservice
spec:
replicas: 1
selector:
matchLabels:
app: personservice
template:
metadata:
labels:
app: personservice
spec:
containers:
- name: personservice
image: microservice-k8s/personmicroservice-k8s:1.0
ports:
- containerPort: 8080
env:
- name: PROFILE
value: "dev"
- name: SERVER_PORT
value: "8080"
- name: ZIPKIN_URI
value: "http://100.120.60.210:9411"
编辑2:
我已经部署了另一个Pod和服务进行测试,并且可以正常工作。 为两个服务都运行此命令 kubectl获得服务人员服务-o json 我发现的唯一差异如下:
非工作服务
"status": {
"loadBalancer": {}
}
工作服务:
"status": {
"loadBalancer": {
"ingress": [
{
"hostname": "localhost"
}
]
}
}
空状态背后的原因是什么?
修改3:
端口转发到Pod并通过http://localhost:7000进行访问正在工作。
kubectl port-forward personservice-5c66cfcb89-dd6l7 7000:8080
这意味着仅服务有问题。
答案 0 :(得分:0)
运行minikube tunnel
以能够直接连接到ip。
答案 1 :(得分:0)
我在稍微不同的情况下转载了您的案件。您正在使用带有Kubernetes的Docker桌面,而我决定使用Minikube进行复制。
我以您的yaml文件为基础来部署nginx服务,但我没有遇到您所描述的问题。 这是我的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: personservice
labels:
app: personservice
spec:
replicas: 1
selector:
matchLabels:
app: personservice
template:
metadata:
labels:
app: personservice
spec:
containers:
- name: personservice
image: nginx
ports:
- containerPort: 80
这是我的服务
apiVersion: v1
kind: Service
metadata:
labels:
app: personservice
name: personservice
namespace: default
spec:
externalTrafficPolicy: Cluster
ports:
- nodePort: 30001
port: 80
protocol: TCP
targetPort: 80
selector:
app: personservice
sessionAffinity: None
type: NodePort
注意:我仅出于方便起见使用端口
80
。
如您所见,这些yaml文件具有与您相同的组件,我可以成功curl
我的nginx应用程序。
user@bf:~$ minikube ip
192.168.39.153
user@bf:~$ curl 192.168.122.36:30001
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
我强烈建议您使用Minikube在其他环境中重现它。有许多advantages关于使用Minikube而不是Docker Desktop的信息。