How to Add static public IP adress to a kubernetes/nginx ingress controller in an AKS cluster without helm

huangapple go评论103阅读模式
英文:

How to Add static public IP adress to a kubernetes/nginx ingress controller in an AKS cluster without helm

问题

我有一个Azure Kubernetes Service集群,并通过以下命令创建了一个公共IP地址:

az network public-ip create --resource-group MC_myResourceGroup_myAKSCluster_eastus --name myAKSPublicIP --sku Standard --allocation-method static --query publicIp.ipAddress -o tsv

我通过以下命令创建了入口控制器:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml

为了尝试将IP地址添加到入口控制器中,我尝试按照这个教程的步骤操作,但由于我没有通过helm安装入口控制器,所以似乎无法正常工作。

重要说明是,没有Azure IP地址时,入口控制器是可以工作的,但我想创建一个静态IP,这样当入口控制器被删除时它不会被删除。

更新:

我按照@silent的建议进行了以下操作:

  1. 访问:https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml
  2. 复制yaml代码并粘贴到一个文件中
  3. 在yaml文件中的以下部分添加@silent提供的行:
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path: /healthz
    service.beta.kubernetes.io/azure-load-balancer-ipv4: <Azure-IP>
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.8.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

当我应用不带@silent提供的注释的文件时,它可以工作,但当然会使用一个随机的IP地址。当我添加注释时,服务的EXTERNAL-IP将保持为<PENDING>。

英文:

I have an Azure Kubernetes Service cluster and created a public IP address via:

> az network public-ip create --resource-group MC_myResourceGroup_myAKSCluster_eastus --name myAKSPublicIP --sku Standard --allocation-method static --query publicIp.ipAddress -o tsv

I created the ingress controller via:

> kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml

To try and add the IP address to the ingress-controller, I tried following this tutorial, but since I have not installed the ingress controller via helm it does not seem to be working.

An important note is that, without the Azure IP address, the ingress controller does work, but I want to create a static IP so that it does not get delete when the ingress controller gets deleted.

Update:

I followed @silent's advice by:

  1. Going to: https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yaml
  2. Copying the yaml code and pasting it in a file
  3. Adding the lines @silent provided in the following piece from the yaml:
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path: /healthz
    service.beta.kubernetes.io/azure-load-balancer-ipv4: &lt;Azure-IP&gt;
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.8.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

When I apply the file without the annotations @silent provided, it works, but of course with a random IP address. When I add the annotations, the service's EXTERNAL-IP will remain &lt;PENDING&gt;.

答案1

得分: 1

你只需要调整你的yaml文件,并设置服务的IP地址(通过注释,因为这是目前推荐的方式):

应该是这样的

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path: /healthz
    service.beta.kubernetes.io/azure-load-balancer-ipv4: 1.2.3.4 # &lt;-- 在这里放入你的IP地址
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.8.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer
英文:

You just need to adjust your yaml file and set the IP address of the service (through annotations, as this is the currently recommended way):

Should be this one

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-health-probe-request-path: /healthz
    service.beta.kubernetes.io/azure-load-balancer-ipv4: 1.2.3.4 # &lt;-- here put your ip
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.8.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

huangapple
  • 本文由 发表于 2023年8月9日 16:58:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定