我想用 Kubernetes 创建一个示例应用程序,但是如果我尝试连接到 Kubernetes 中的响应式服务,我会被拒绝连接。
例如,如果我从另一个 pod 连接到http://random-generator-svc:5050/,我会收到一个错误,提示连接被拒绝。
这是为随机生成器创建服务和部署的 yaml 文件:
apiVersion: v1
kind: Service
metadata:
name: random-generator-svc
labels:
app: rand-gen
spec:
selector:
app: rand-gen
type: NodePort
ports:
- protocol: "TCP"
port: 5050
targetPort: 5050
name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: random-generator-deployment
labels:
app: rand-gen
spec:
replicas: 2
selector:
matchLabels:
app: rand-gen
template:
metadata:
labels:
app: rand-gen
spec:
containers:
- name: random-generator-container
image: toky03/random-generator-image:1.2
ports:
- containerPort: 5050
这是指定“调用者”应用程序的服务和部署的 yaml 文件:
apiVersion: v1
kind: Service
metadata:
name: middle-tier-svc
labels:
app: rand-gen
spec:
selector:
app: rand-gen
type: NodePort
ports:
- protocol: "TCP"
port: 7070
targetPort: 7070
name: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: middle-tier-controller
labels:
app: rand-gen
spec:
replicas: 1
selector:
matchLabels:
app: rand-gen
template:
metadata:
labels:
app: rand-gen
spec:
containers:
- name: random-controller-container
image: toky03/random-controller-image:1.2
ports:
- containerPort: 7070
我将类型更改NodePort
为尝试是否也存在此错误,但我能够从集群外部访问服务。我的 Kubernetes DNS 解析器可能有问题吗?
非常感谢您的帮助。