This topic describes how to deploy an Ingress application on a virtual node of a Kubernetes cluster. With the virtual node, the Kubernetes cluster can provide the application with scalable and unlimited computing capacity without the need to create new nodes.

Prerequisites

A virtual node is deployed in your Kubernetes cluster. For more information, see Virtual nodes.

The virtual-node-affinity-injection: enabled label is added to the target namespace. For more information, see Virtual nodes.

Procedure

  1. Log on to the Container Service console.
  2. In the left-side navigation pane under Container Service - Kubernetes, choose Applications > Deployments. On the Deployments page that appears, click Create from Template in the upper-right corner.
  3. Select the cluster and namespace, select a sample template or Custom from the Sample Template drop-down list, and then click Create.
    Sample template
    You can use the following YAML template to create an Ingress application:
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: coffee
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: coffee
      template:
        metadata:
          labels:
            app: coffee
        spec:
          containers:
          - name: coffee
            image: nginxdemos/hello:plain-text
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: coffee-svc
    spec:
      ports:
      - port: 80
        targetPort: 80
        protocol: TCP
      selector:
        app: coffee
      clusterIP: None
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: tea
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: tea
      template:
        metadata:
          labels:
            app: tea
        spec:
          containers:
          - name: tea
            image: nginxdemos/hello:plain-text
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: tea-svc
      labels:
    spec:
      ports:
      - port: 80
        targetPort: 80
        protocol: TCP
      selector:
        app: tea
      clusterIP: None
    ---
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: cafe-ingress
    spec:
      rules:
      - host: cafe.example.com
        http:
          paths:
          - path: /tea
            backend:
              serviceName: tea-svc
              servicePort: 80
          - path: /coffee
            backend:
              serviceName: coffee-svc
              servicePort: 80

Verify the results

  • In the left-side navigation pane under Container Service - Kubernetes, choose Applications > Deployments. On the Deployments page that appears, select the target cluster and namespace. You can view the coffee and tea deployments that you created.Applications
  • In the left-side navigation pane under Container Service - Kubernetes, choose Applications > Pods. On the Pods page that appears, select the target cluster and namespace. You can view the pods that run on the virtual-kubelet node.Virtual-kubelet node
  • In the left-side navigation pane under Container Service - Kubernetes, choose Ingresses and Load Balancing > Ingresses. On the Ingress page that appears, select the target cluster and namespace. You can view the Ingress application that you created.Ingress
  • To verify that the created Ingress application can be accessed, run the following commands:
    kubectl -n vk get ing
    curl -H "Host:cafe.example.com" <EXTERNAL_IP>/tea
    curl -H "Host:cafe.example.com" <EXTERNAL_IP>/coffee
    Ingress application