我正在阅读“ Kubernetes in Action”并尝试从本书中提取样本。我已经创建了一个吊舱:
apiVersion: v1
kind: Pod
metadata:
name: kubia-manual
spec:
containers:
- image: luksa/kubia
name: kubia
ports:
- containerPort: 8080
protocol: TCP
和服务:
apiVersion: v1
kind: Service
metadata:
name: kubia
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: kubia
这是我当前的状态:
# ~/work_folder/code/kubernetes/kubernetes-in-action/Chapter05 ±master » k get pods
NAME READY STATUS RESTARTS AGE
azure-vote-back-77dff7bbd5-z22ff 1/1 Running 0 2d18h
azure-vote-front-5bc759676c-8v8zp 1/1 Running 0 2d18h
fortune 2/2 Running 0 2d8h
kubia-manual 1/1 Running 0 2d7h
# ~/work_folder/code/kubernetes/kubernetes-in-action/Chapter05 ±master » k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-back ClusterIP 10.0.216.167 <none> 6379/TCP 2d18h
azure-vote-front LoadBalancer 10.0.125.207 20.40.139.148 80:31909/TCP 2d18h
fortune ClusterIP 10.0.236.103 <none> 80/TCP 2d7h
fortune-nodeport NodePort 10.0.69.172 <none> 80:30132/TCP 2d7h
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 2d18h
kubia ClusterIP 10.0.234.108 <none> 80/TCP 8m58s
现在,我正在尝试从集群内部的pod调用服务:
# ~/work_folder/code/kubernetes/kubernetes-in-action/Chapter05 ±master » k exec kubia-manual -- curl -s 10.0.234.108 7 ↵
command terminated with exit code 7
# ~/work_folder/code/kubernetes/kubernetes-in-action/Chapter05 ±master » k exec kubia-manual -- curl 10.0.234.108 7 ↵
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to 10.0.234.108 port 80: Connection refused
command terminated with exit code 7
为什么我失败了,怎么解决?
答案 0 :(得分:3)
服务中有一个选择器app: kubia
。因此,pod需要带有标签app=kubia
,否则该服务将没有Endpoints
填充Pod IP,并且不知道将流量发送到哪里。您可以使用kubectl describe svc kubia
命令在Endpoints
部分中检查服务是否具有Pod IP。
检查docs,以使用服务进行更多调试。