我是 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 获取 pod
当我试图用邮递员击中它时
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 get service personservice -o json 我发现的唯一差异如下:
非工作服务
"status": {
"loadBalancer": {}
}
工作服务:
"status": {
"loadBalancer": {
"ingress": [
{
"hostname": "localhost"
}
]
}
}
空置状态背后的原因可能是什么?
编辑3:
端口转发到 pod 并通过http://localhost:7000访问它正在工作。
kubectl port-forward personservice-5c66cfcb89-dd6l7 7000:8080
这意味着只有服务有问题。