This topic describes how to deploy a service.

Prerequisites

Background information

With canary deployment or blue/green deployment, you can run the new version of a service in an environment identical to the environment where the old version of the service operates. Specifically, you can set a rule to direct part of the traffic that is destined for the old version to the new version of the service without affecting the old version. After the new version of the service operates normally for a period, you can direct the remaining traffic to the the new version of the service. In the following steps, a service named lod-nginx is created as the old version of the sample service.

Procedure

  1. Log on to the Container Service console.
  2. In the left-side navigation pane under Container Service-Kubernetes, choose Application > Deployment.
  3. In the upper-right corner, click Create from Template.

  4. Select the target cluster and namespace, select a sample template or customize a template, and then click Create.

    In this example, a template is orchestrated to deploy an Nginx application that contains the required deployment, the target service, and an Ingress. The deployment exposes its port through NodePort. The Ingress provides externally accessible services. The orchestration template is as follows:

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: old-nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          run: old-nginx
      template:
        metadata:
          labels:
            run: old-nginx
        spec:
          containers:
          - image: registry.cn-hangzhou.aliyuncs.com/xianlu/old-nginx
            imagePullPolicy: Always
            name: old-nginx
            ports:
            - containerPort: 80
              protocol: TCP
          restartPolicy: Always
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: old-nginx
    spec:
      ports:
      - port: 80
        protocol: TCP
        targetPort: 80
      selector:
        run: old-nginx
      sessionAffity: None
      type: NodePort
    ---
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
        name: gray-release
    spec:
      rules:
      - host: www.example.com
        http:
          paths:
          # The service of an earlier version.
          - path: /
            backend:
              serviceName: old-nginx
              servicePort: 80
  5. In the left-side navigation pane under Container Service-Kubernetes, choose Ingresses and Load Balancing > Ingresses.
    You can see that the virtual host name points to old-nginx.

  6. Log on to the Master node and run the curl command to view the Ingress.
    curl -H "Host: www.example.com" http://<EXTERNAL_IP> 
    Note You can obtain the value of <EXTERNAL_IP> by using either of the following two methods:
    • Run the following command:
      kubectl get ingress
    • In the left-side navigation pane under Container Service-Kubernetes, choose Ingresses and Load Balancing > Ingresses to view the endpoint information of the target Ingress.