微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 nginx-ingress 将我的外部域“uat.test.com”添加到我的 kubernetes 集群?

如何解决如何使用 nginx-ingress 将我的外部域“uat.test.com”添加到我的 kubernetes 集群?

我是 kubernetes 的新手,对于来自 Godaddy 的外部域的入口 Nginx 有问题。它被称为“https://uat.test.com”。我为 nginx-ingress 创建了一些 yaml,但我做不到。如何使用 nginx-ingress 将“uat.test.com”添加到我的 kubernetes 集群?

下面;它们是我在有趣而有压力的冒险中迈出的一步。

  1. 创建组和命名空间:
az group create --name aks-group --location eastus2

az aks create --resource-group aks-group --name aks-cluster --node-count 3 --generate-ssh-keys -s Standard_B2ms --disable-rbac

kubectl create namespace ingress-basic
  1. 凭据:
az aks get-credentials -g aks-group -n aks-cluster

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-Nginx/controller-v0.43.0/deploy/static/provider/cloud/deploy.yaml
 
az aks get-credentials -g aks-group -n aks-cluster

kubectl --namespace ingress-basic get services -o wide -w nginx-ingress-ingress-Nginx-controller
  1. 安装 ingress-Nginx
helm install ingress-Nginx ingress-Nginx/ingress-Nginx
   
helm repo update
    
helm install nginx-ingress ingress-Nginx/ingress-Nginx --namespace ingress-basic --set controller.replicaCount=2
     
kubectl --namespace ingress-basic get services -o wide -w nginx-ingress-ingress-Nginx-control

enter image description here

aks-helloworld-one.yaml :

apiVersion: apps/v1
kind: Deployment
Metadata:
  name: aks-helloworld-one  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aks-helloworld-one
  template:
    Metadata:
      labels:
        app: aks-helloworld-one
    spec:
      containers:
      - name: aks-helloworld-one
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "Welcome to Azure Kubernetes Service (AKS)"
---
apiVersion: v1
kind: Service
Metadata:
  name: aks-helloworld-one  
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: aks-helloworld-one
kubectl apply -f aks-helloworld-one.yaml --namespace ingress-basic

aks-helloworld-two.yml:

apiVersion: apps/v1
kind: Deployment
Metadata:
  name: aks-helloworld-two  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aks-helloworld-two
  template:
    Metadata:
      labels:
        app: aks-helloworld-two
    spec:
      containers:
      - name: aks-helloworld-two
        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1
        ports:
        - containerPort: 80
        env:
        - name: TITLE
          value: "AKS Ingress Demo"
---
apiVersion: v1
kind: Service
Metadata:
  name: aks-helloworld-two  
spec:
  type: ClusterIP
  ports:
  - port: 80
  selector:
    app: aks-helloworld-two
kubectl apply -f aks-helloworld-two.yaml --namespace ingress-basic

hello-world-ingress.yml:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
Metadata:
  name: hello-world-ingress
  namespace: ingress-basic
  annotations:
    kubernetes.io/ingress.class: Nginx
    Nginx.ingress.kubernetes.io/ssl-redirect: "false"
    Nginx.ingress.kubernetes.io/use-regex: "true"
    Nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: uat.test.com 
    http:
      paths:
      - backend:
          serviceName: aks-helloworld-one
          servicePort: 80
        path: /hello-world-one(/|$)(.*)
      - backend:
          serviceName: aks-helloworld-two
          servicePort: 80
        path: /hello-world-two(/|$)(.*)
      - backend:
          serviceName: aks-helloworld-one
          servicePort: 80
        path: /(.*)
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
Metadata:
  name: hello-world-ingress-static
  namespace: ingress-basic
  annotations:
    kubernetes.io/ingress.class: Nginx
    Nginx.ingress.kubernetes.io/ssl-redirect: "false"
    Nginx.ingress.kubernetes.io/rewrite-target: /static/$2
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: aks-helloworld-one
          servicePort: 80
        path: /static(/|$)(.*)
kubectl apply -f hello-world-ingress.yaml

当我写地址“https://uat.test.com”

结果或错误

enter image description here

解决方法

// 如评论中所述

您需要将集群入口控制器的公共 IP 地址绑定到您的 DNS 名称的某个地方。这不会发生在 AKS(或您的 k8s 配置中的任何地方)中。您需要与您的 DNS 提供商联系。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。