Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure kubernetes服务负载平衡器外部IP不可访问_Azure_Docker_Kubernetes_Azure Aks - Fatal编程技术网

Azure kubernetes服务负载平衡器外部IP不可访问

Azure kubernetes服务负载平衡器外部IP不可访问,azure,docker,kubernetes,azure-aks,Azure,Docker,Kubernetes,Azure Aks,我是Kubernetes的新手,正在测试Django“Hello world”应用程序部署示例。使用docker compose,我可以在浏览器上访问地狱世界页面,但我需要使用Kubernetes。所以我测试了两个选项,但都不起作用。 1) 我创建了一个Azure CICD管道,使用以下Dockerfile在ACR中构建和推送映像 FROM python:3.8 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 RUN mkdir /hel

我是Kubernetes的新手,正在测试Django“Hello world”应用程序部署示例。使用docker compose,我可以在浏览器上访问地狱世界页面,但我需要使用Kubernetes。所以我测试了两个选项,但都不起作用。 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" ]
管道成功完成并将映像上载到存储库中

现在我使用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
部署和服务已创建,但当我尝试通过浏览器访问LB服务的外部IP时,页面无法访问。我使用了外部ip:端口,但它不工作。 你知道为什么会这样吗

2) 我使用了相同的Dockerfile,但使用了不同的部署文件(将映像更改为本地创建的映像并删除了LB服务)将应用程序部署到本地Kubernetes。部署文件如下所示

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

它创建了部署和服务,但没有为NodePort服务分配外部IP,因此我无法确定应该选择什么服务来测试应用程序是否成功。我知道我不能选择LB,因为它不在本地,我需要使用云服务进行部署。

只需将您的服务配置为
LoadBalancer类型,并执行正确的端口映射:

apiVersion: v1
kind: Service
metadata:
  name: django-helloworld-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8000
  selector:
    app: django-helloworld

只需将您的服务配置为
负载平衡器类型,并执行正确的端口映射:

apiVersion: v1
kind: Service
metadata:
  name: django-helloworld-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8000
  selector:
    app: django-helloworld

确保部署也有相关的健康吊舱(它们显示为
正在运行
,并且名称旁边有
1/1
)。如果没有,请确保您的集群可以成功地从
acrshgpdev1.azurecr.io
注册表中提取;您可以按照以下步骤直接将AKS群集与ACR注册表集成:


或者通过手动将AKS群集的SP添加到ACR上的
读卡器
角色中。

确保部署也有相关的健康POD(它们显示为
正在运行
,并且名称旁边有
1/1
)。如果没有,请确保您的集群可以成功地从
acrshgpdev1.azurecr.io
注册表中提取;您可以按照以下步骤直接将AKS群集与ACR注册表集成:


或者通过手动将AKS群集的SP添加到ACR上的
读卡器
角色中。

因此添加一个targetport,当我到达外部IP时,我会收到一个“DisallowedHost”错误。因此,我将外部IP添加到setting.py allowed主机中,重新构建映像并使用部署文件进行部署。现在我看到外部IP不同了。每次在Azure上创建的loadbalancer上,我都会看到IP发生变化。我不确定什么是
settings.py
,但如果你是这样问的,你只需要收听
0.0.0:8000
。外部ip不会更改,除非您完全删除服务并添加targetport,并且当我访问外部ip时,会出现“DisallowedHost”错误。因此,我将外部IP添加到setting.py allowed主机中,重新构建映像并使用部署文件进行部署。现在我看到外部IP不同了。每次在Azure上创建的loadbalancer上,我都会看到IP发生变化。我不确定什么是
settings.py
,但如果你是这样问的,你只需要收听
0.0.0:8000
。外部ip不会更改,除非您完全删除该服务