You do not need to create or manage nodes in serverless Kubernetes (ASK) clusters. This frees you from maintaining cloud resources of your applications and allows you to focus on your business development instead of managing the underlying infrastructure. This topic describes how to deploy web applications in ASK clusters.

Background information

ASK cluster support standard Kubernetes semantics and API operations. You can create cluster resources with a few clicks, such as Deployments, StatefulSets, Jobs, services, Ingresses, and custom resources. You can also use Helm to deploy a variety of Kubernetes-native applications in ASK clusters.

Procedure

  1. Use kubectl to connect to a cluster.
  2. Create an nginx.yaml file and copy the following content into the file.
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx-service
    spec:
      ports:
      - port: 80
        protocol: TCP
      selector:
        app: nginx
      type: LoadBalancer
    ---
    apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
      name: nginx-deploy
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image:  nginx:alpine
            ports:
            - containerPort: 80
            resources:
              requests:
                cpu: "2"
                memory: "4Gi"
  3. Run the following command to deploy an NGINX application in the ASK cluster.
    kubectl apply -f nginx.yaml
    # Output:
    service/nginx-service created
    deployment.apps/nginx-deploy created
  4. Run the following command to view the status of pods and services deployed in the cluster. You can use the IP address of the created SLB instance to access the NGINX application.
    kubectl get pod
    # Output:
    NAME                            READY   STATUS    RESTARTS   AGE
    nginx-deploy-55d8dcf755-bxk8n   1/1     Running   0          36s
    nginx-deploy-55d8dcf755-rchhq   1/1     Running   0          36s
    
    kubectl get svc
    # Output:
    NAME            TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
    kubernetes      ClusterIP      172. **. *.*     <none>        443/TCP        10d
    nginx-service   LoadBalancer   172.19. *. ***   47.57. **. **   80:32278/TCP   39s
    
    curl 47.57. **. **
    # Output:
    <! DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx! </title>
    ...
    </html>
  5. Run the following command to scale out the NGINX Deployment.
    kubectl get deploy
    # Output:
    NAME           READY   UP-TO-DATE   AVAILABLE   AGE
    nginx-deploy   2/2     2            2           9m32s
    
    kubectl scale deploy nginx-deploy --replicas=10
    # Output:
    deployment.extensions/nginx-deploy scaled
    
    kubectl get pod
    # Output:
    NAME                            READY   STATUS    RESTARTS   AGE
    nginx-deploy-55d8dcf755-8jlz2   1/1     Running   0          39s
    nginx-deploy-55d8dcf755-9jbzk   1/1     Running   0          39s
    nginx-deploy-55d8dcf755-bqhcz   1/1     Running   0          38s
    nginx-deploy-55d8dcf755-bxk8n   1/1     Running   0          10m
    nginx-deploy-55d8dcf755-cn6x9   1/1     Running   0          38s
    nginx-deploy-55d8dcf755-jsqjn   1/1     Running   0          38s
    nginx-deploy-55d8dcf755-lhp8l   1/1     Running   0          38s
    nginx-deploy-55d8dcf755-r2clb   1/1     Running   0          38s
    nginx-deploy-55d8dcf755-rchhq   1/1     Running   0          10m
    nginx-deploy-55d8dcf755-xspnt   1/1     Running   0          38s
  6. Run the following command to configure scaling settings for Horizontal Pod Autoscaler (HPA). HPA automatically scales out the Deployment when the CPU usage exceeds the specified threshold.
    kubectl scale deploy nginx-deploy --replicas=1
    # Output:
    deployment.extensions/nginx-deploy scaled
    
    kubectl get pod
    # Output:
    NAME                            READY   STATUS    RESTARTS   AGE
    nginx-deploy-55d8dcf755-rchhq   1/1     Running   0          16m
    
    kubectl autoscale deployment nginx-deploy --cpu-percent=50 --min=1 --max=10
    # Output:
    horizontalpodautoscaler.autoscaling/nginx-deploy autoscaled
    
    kubectl get hpa
    # Output:
    NAME           REFERENCE                 TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
    nginx-deploy   Deployment/nginx-deploy   0%/30%    1         10        1          35s