简体   繁体   English

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

[英]How can I add my external domain “uat.test.com ” to my kubernetes cluster by using nginx-ingress?

I am new for kubernetes and Have an issue for ingress nginx for external domain from godaddy.我是 kubernetes 的新手,并且对于来自 godaddy 的外部域的入口 nginx 有问题。 it is called " https://uat.test.com ".I created some yaml for nginx-ingress but I couldn't do that.它被称为“ https://uat.test.com ”。我为 nginx-ingress 创建了一些 yaml 但我做不到。 How can I add "uat.test.com " to my kubernetes cluster by using nginx-ingress?如何使用 nginx-ingress 将“uat.test.com”添加到我的 kubernetes 集群?

Below;以下; They are my steps for my funny and stressful advantures.它们是我有趣和有压力的冒险的步骤。

  1. Create group and namespace:创建组和命名空间:
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. Credentials:证书:
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. install ingress-nginx:安装入口-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

在此处输入图像描述 aks-helloworld-one.yaml: 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: 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: 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

When I write address "https://uat.test.com "当我写地址“https://uat.test.com”

Result or Error:结果或错误: 在此处输入图像描述

// as discussed in the comments // 如评论中所述

somewhere you need to bind the public IP address of your clusters ingress controller to your DNS name.在某个地方,您需要将集群入口 controller 的公共 IP 地址绑定到您的 DNS 名称。 That does not happen in AKS (or anywhere in your k8s configs).这不会发生在 AKS(或您的 k8s 配置中的任何地方)中。 You need to do that with your DNS provider.您需要使用 DNS 提供程序来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM