im试图访问我们在Azure上的Kubernetes群集上的部署。这是一个Azure Kubernetes服务(AKS)。这是部署的配置文件以及应公开部署的服务。
apiVersion: apps/v1
kind: Deployment
metadata:
name: mira-api-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mira-api
template:
metadata:
labels:
app: mira-api
spec:
containers:
- name: backend
image: registry.gitlab.com/izit/mira-backend
ports:
- containerPort: 8080
name: http
protocol: TCP
imagePullSecrets:
- name: regcred
apiVersion: v1
kind: Service
metadata:
name: mira-api-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
run: mira-api
当我应用这些配置后检查群集时,我看到Pod正常运行。此外,还将创建服务并分配了公共IP。
此部署后,我看不到任何请求得到处理。我在浏览器中收到一条错误消息,指出该站点无法访问。有什么想法我可能配置错误吗?
您的服务选择器标签和吊舱标签不匹配。
您在部署的pod模板中具有app: mira-api
标签,但在服务的标签选择器中具有run: mira-api
。
如下更改服务选择器标签以匹配吊舱标签。
apiVersion: v1
kind: Service
metadata:
name: mira-api-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: mira-api
[要确保您的服务是否选择了后端Pod,可以运行kubectl describe svc <svc name>
命令并检查是否列出了任何Endpoints
。
# kubectl describe svc postgres
Name: postgres
Namespace: default
Labels: app=postgres
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"postgres"},"name":"postgres","namespace":"default"},"s...
Selector: app=postgres
Type: ClusterIP
IP: 10.106.7.183
Port: default 5432/TCP
TargetPort: 5432/TCP
Endpoints: 10.244.2.117:5432 <------- This line
Session Affinity: None
Events: <none>