云容器引擎 CCE-Nginx Ingress配置应用流量镜像:步骤1:创建工作负载,并通过Ingress对外暴露服务

时间:2024-05-31 08:37:35

步骤1:创建工作负载,并通过Ingress对外暴露服务

  1. 在cluster-1集群中部署应用,并测试访问。

    复制以下文件保存到nginx-deploy.yaml文件。
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        version: v1
      name: nginx
      namespace: default
    spec:
      selector:
        matchLabels:
          app: nginx
          version: v1
      template:
        metadata:
          labels:
            app: nginx
            version: v1
        spec:
          containers:
            - name: container-1
              image: nginx:latest
              imagePullPolicy: IfNotPresent
          terminationGracePeriodSeconds: 30
          dnsPolicy: ClusterFirst
      replicas: 1
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
      namespace: default
    spec:
      selector:
        app: nginx
      externalTrafficPolicy: Cluster
      ports:
        - name: cce-service-0
          targetPort: 80
          port: 80
          protocol: TCP
      type: NodePort
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: nginx
      namespace: default
    spec:
      rules:
        - host: example.com
          http:
            paths:
              - path: /
                backend:
                  service:
                    name: nginx
                    port:
                      number: 80
                property:
                  ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH
                pathType: ImplementationSpecific
      ingressClassName: nginx

  2. 对cluster-1集群执行以下命令,创建工作负载。

    kubectl apply -f nginx-deploy.yaml

  3. 在cluster-2集群中部署相同的应用,重复执行以上命令,创建相同的工作负载。
support.huaweicloud.com/usermanual-cce/cce_10_0854.html