[英]Azure kubernetes service loadbalancer external IP not accessible
I am new to the world of Kubernetes and was testing a sample Django "Hello world" app deployment.我是 Kubernetes 世界的新手,正在测试示例 Django“Hello world”应用程序部署。 Using docker-compose I was able to access the hell world page on a browser but I need to use Kubernetes.
使用 docker-compose 我能够在浏览器上访问地狱世界页面,但我需要使用 Kubernetes。 So I tested two options and none of them worked.
所以我测试了两个选项,但都没有奏效。 1) I created an Azure CICD pipeline to build and push the image in ACR using the following Dockerfile,
1) 我创建了一个 Azure CICD 管道来使用以下 Dockerfile 在 ACR 中构建和推送映像,
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN mkdir /hello_world
WORKDIR /hello_world
COPY . /hello_world/
RUN pip install -r requirements.txt
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]
The pipeline completes successfully and uploads the image in the repository.管道成功完成并将图像上传到存储库中。
Now I use kubectl to deploy using the deployment file,现在我使用 kubectl 使用部署文件进行部署,
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-helloworld
spec:
replicas: 3
selector:
matchLabels:
app: django-helloworld
template:
metadata:
labels:
app: django-helloworld
spec:
containers:
- name: django-helloworld
image: acrshgpdev1.azurecr.io/django-helloworld:194
#imagePullPolicy: Always
ports:
- containerPort: 8000
---
apiVersion: v1
kind: Service
metadata:
name: django-helloworld-service
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: django-helloworld
The deployment and service are created but when I try to access the external IP of the LB service through a browser the page is inaccessible.部署和服务已创建,但是当我尝试通过浏览器访问 LB 服务的外部 IP 时,该页面无法访问。 I used the external ip:port and it didn't work.
我使用了外部 ip:port,但它不起作用。 Any thoughts why would this be happening?
任何想法为什么会发生这种情况?
2) I used the same Dockerfile but a different deployment file(changed the image to the locally created image & removed LB service) to deploy the app to my local Kubernetes. 2)我使用了相同的 Dockerfile 但使用了不同的部署文件(将映像更改为本地创建的映像并删除了 LB 服务)将应用程序部署到我的本地 Kubernetes。 the deployment file was as follows,
部署文件如下,
apiVersion: v1
kind: Service
metadata:
name: django-helloworld-service
spec:
selector:
app: django-helloworld
ports:
- protocol: TCP
port: 80
targetPort: 30800
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-helloworld
spec:
replicas: 3
selector:
matchLabels:
app: django-helloworld
template:
metadata:
labels:
app: django-helloworld
spec:
containers:
- name: django-helloworld
image: django-helloworld:1.0
#imagePullPolicy: Always
ports:
- containerPort: 8000
It creates the deployment and service but doesn't assign an external IP to the NodePort service so I am not able to figure out what service should I choose to test the app is successful.它会创建部署和服务,但不会为 NodePort 服务分配外部 IP,因此我无法确定应该选择什么服务来测试应用程序是否成功。 I know I can't choose a LB as it doesn't go locally and I need to deploy using a cloud service.
我知道我不能选择 LB,因为它不在本地,我需要使用云服务进行部署。
just configure your service to be of type LoadBalancer
and do a proper port mapping:只需将您的服务配置为
LoadBalancer
类型并进行适当的端口映射:
apiVersion: v1
kind: Service
metadata:
name: django-helloworld-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8000
selector:
app: django-helloworld
https://kubernetes.io/docs/concepts/services-networking/service/ https://kubernetes.io/docs/concepts/services-networking/service/
Make sure the deployment has associated healthy pods too (they show as Running
and with 1/1
next to their name).确保部署也关联了健康的 pod(它们显示为
Running
并且名称旁边带有1/1
)。 If there aren't, make sure your cluster can successfully pull from acrshgpdev1.azurecr.io
registry;如果没有,请确保您的集群可以成功从
acrshgpdev1.azurecr.io
注册表中拉取; you can integrate directly an AKS cluster with an ACR registry following this article :您可以按照本文直接将 AKS 集群与 ACR 注册表集成:
az aks update -n myAKSCluster -g myResourceGroup --attach-acr acrshgpdev1.azurecr.io
or by adding the SP of the AKS cluster manually to the Reader
role on the ACR.或者通过手动将 AKS 群集的 SP 添加到 ACR 上的
Reader
角色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.