我创建了一个Web服务并将其嵌入到Azure容器中,并使用Kubernetes对其进行管理。与Microsoft发布的AKS教程相似。当我尝试通过AKS提供的公共IP访问我的服务时,无法访问该服务。 Pod正常运行,服务日志显示没有问题,Web服务器正常运行。可能是什么问题呢?以下是我的yaml文件和CLI输出
kubectl get pods
NAME READY STATUS RESTARTS AGE
books-back-85c6fd64fd-wjxff 1/1 Running 0 3d
books-front-68448dbfdb-cbmfs 1/1 Running 0 24m
-----------------------------------------------------------
kubectl get logs books-front-68448dbfdb-cbmf
Book {'Title': 'Atomic Habits', 'Author': 'Mark Johnson'} added
Book {'Title': 'If Tomorrow Comes', 'Author': 'Sidney Sheldon'} added
books: [{"Title": "Atomic Habits", "Author": "Mark Johnson"}]
* Serving Flask app "server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
-----------------------------------------------------------------------
kubectl get service
books-back ClusterIP 10.0.235.217 <none> 6379/TCP 3d
books-front LoadBalancer 10.0.165.13 52.168.10.232 80:31233/TCP 3d
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 3d
-----------------------------------------------------------------------------
My Yaml file
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: books-back
spec:
replicas: 1
template:
metadata:
labels:
app: books-back
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: books-back
image: redis
ports:
- containerPort: 6379
name: redis
---
apiVersion: v1
kind: Service
metadata:
name: books-back
spec:
ports:
- port: 6379
selector:
app: books-back
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: books-front
spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: books-front
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: books-front
image: bookservice.azurecr.io/books-front:v1
ports:
- containerPort: 80
resources:
requests:
cpu: 250m
limits:
cpu: 500m
env:
- name: REDIS
value: "books-back"
---
apiVersion: v1
kind: Service
metadata:
name: books-front
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: books-front
一切似乎都很好。但是,当我访问52.168.10.232时,服务没有响应。
答案 0 :(得分:1)
从书本前端窗格的日志中,您的应用程序侦听端口5000,但为容器公开了端口80。它导致无法访问。
您只需要进行更改即可在部署books-front
和服务books-front
中公开端口5000,如下所示:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: books-front
spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: books-front
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: books-front
image: bookservice.azurecr.io/books-front:v1
ports:
- containerPort: 5000
resources:
requests:
cpu: 250m
limits:
cpu: 500m
env:
- name: REDIS
value: "books-back"
---
apiVersion: v1
kind: Service
metadata:
name: books-front
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 5000
selector:
app: books-front