简体   繁体   English

无法访问 Azure kubernetes 服务负载均衡器外部 IP

[英]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.

相关问题 如何使用 static 外部 IP 用于 Azure ZB76E98AF9AAA680979BF5A65B2D5 - How to use static External IP for Azure kubernetes LoadBalancer? 无法通过头盔访问AKS上的Kubernetes LoadBalancer服务 - Kubernetes LoadBalancer service on AKS via helm is not accessible 如何使用LoadBalancer服务从Azure Kubernetes中获取客户端IP地址 - How to get client IP address from inside a Azure Kubernetes with a LoadBalancer service 在 azure App Service 中将 Azure Kubernetes 外部 IP 列入白名单 - Whitelisting Azure Kubernetes external IP in azure App Service Azure Kubernetes - 带有 Https 服务的内部负载均衡器? - Azure Kubernetes - Internal LoadBalancer with Https Service? 我在 Azure Kubernetes 上的外部 IP 服务不起作用 - My external IP on Azure Kubernetes Service doesn't work Kube.netes:AKS 上的某些服务(LoadBalancer)正在等待外部 IP - Kubernetes: External-IP is pending for some services(LoadBalancer) on AKS 如何为 Azure Kubernetes 集群创建 TCP/IP 负载均衡器/应用程序网关 - How to create TCP/IP loadbalancer/applicationgateway for Azure Kubernetes cluster Kubernetes中的节点之间无法访问服务IP - Service IP is not accessible across nodes in kubernetes Azure AKS 负载均衡器使用同一 IP 上的服务为多个 pod 提供服务 - Azure AKS Loadbalancer serving multiple pods using service on same IP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM