我在一个pod中创建了一个YAML文件,其中包含三个图像(它们需要通过127.0.0.1进行通信)似乎它一切正常。我在yaml文件中定义了一个nodeport。
有一个部署定义applications
它包含三个图像:
我已经定义了三个服务,每个容器一个。在那里,我已经定义了NodePort
类型来访问它。
所以我检索了服务以获取端口号:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
contacts-db 10.103.67.74 <nodes> 3306:30241/TCP 1d
front-end 10.107.226.176 <nodes> 80:32195/TCP 1d
net-core 10.108.146.87 <nodes> 5000:30245/TCP 1d
我在浏览器中导航到http://:32195并且它一直在加载。它没有连接。这是完整的Yaml文件:
---
apiVersion: v1
kind: Namespace
metadata:
name: three-tier
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: applications
labels:
name: applications
namespace: three-tier
spec:
replicas: 1
template:
metadata:
labels:
name: applications
spec:
containers:
- name: contacts-db
image: mysql/mysql-server #TBD
env:
- name: MYSQL_ROOT_PASSWORD
value: quintor
- name: MYSQL_DATABASE
value: quintor #TBD
ports:
- name: mysql
containerPort: 3306
- name: front-end
image: xanvier/angularfrontend #TBD
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 80
- name: net-core
image: xanvier/contactsapi #TBD
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: contacts-db
labels:
name: contacts-db
namespace: three-tier
spec:
type: NodePort
ports:
# the port that this service should serve on
- port: 3306
targetPort: 3306
selector:
name: contacts-db
---
apiVersion: v1
kind: Service
metadata:
name: front-end
labels:
name: front-end
namespace: three-tier
spec:
type: NodePort
ports:
- port: 80
targetPort: 80 #nodePort: 30001
selector:
name: front-end
---
apiVersion: v1
kind: Service
metadata:
name: net-core
labels:
name: net-core
namespace: three-tier
spec:
type: NodePort
ports:
- port: 5000
targetPort: 5000 #nodePort: 30001
selector:
name: net-core
---
答案 0 :(得分:5)
服务的选择器与您的广告连播的标签相匹配。在您的情况下,定义的选择器指向容器,这些容器在选择pod时无效。
您必须重新定义服务以使用一个选择器或将容器拆分为不同的Deployments / Pods。
要查看为服务定义的选择器是否有效,您可以使用以下命令检查它们:
kubectl get pods -l key=value
如果结果为空,您的服务也会遇到空白。