Updated on 2023-12-21 GMT+08:00

Getting Started

Overview

This section describes the procedure of calling APIs to create a workload from an Nginx image.

The open source image Nginx is used. The container specifications are 0.25 vCPUs and 512 MB of memory, and the workload is associated with a load balancer to allow access from the Internet.

For details about how to call APIs, see Calling APIs.

Procedure

  1. Call the API described in Creating a Namespace to create a namespace.
  2. Call the API described in Creating a Network to create a network, and associate the network with a VPC and subnet.
  3. Call the API described in Creating a Deployment to create an Nginx workload.

Creating a Nginx Workload

  1. Call the API described in Creating a Namespace to create a namespace of the GPU-accelerated type.

    {
        "apiVersion": "v1",
        "kind": "Namespace",
        "metadata": {
            "name": "namespace-test",
            "annotations": {
                "namespace.kubernetes.io/flavor": "gpu-accelerated"
            }
        },
        "spec": {
            "finalizers": [
                "kubernetes"
            ]
        }
    }

    You must specify the following parameters:

    • name: namespace name.
    • namespace.kubernetes.io/flavor: namespace type. Currently, gpu-accelerated and general-computing are supported. GPUs can be used in namespaces of the GPU-accelerated type.

  2. Call the API described in Creating a Network to create a network, and associate the network with a VPC and subnet.

    {
        "apiVersion": "networking.cci.io/v1beta1",
        "kind": "Network",
        "metadata": {
            "name": "test-network",
            "annotations": {
                "network.alpha.kubernetes.io/default-security-group": "security-group-id",
                "network.alpha.kubernetes.io/domain-id": "domain-id",
                "network.alpha.kubernetes.io/project-id": "project-id"
            }
        },
        "spec": {
            
            "cidr": "192.168.0.0/24",
            "attachedVPC": "vpc-id",
            "networkID": "network-id",
            "subnetID": "subnet-id",
            "networkType": "underlay_neutron"
        }
    }

    You must specify the following parameters:

    • name: name of a network object.
    • network.alpha.kubernetes.io/default-security-group: security group ID, which can be obtained on the Security Groups page.
    • network.alpha.kubernetes.io/domain-id: account ID, which can be obtained by following the procedure in Obtaining an Account ID.
    • network.alpha.kubernetes.io/project-id: project ID, which can be obtained by following the procedure in Obtaining a Project ID.
    • cidr: available subnet CIDR in a VPC.
    • attachedVPC: ID of the VPC to which the namespace belongs, which can be obtained on the Virtual Private Cloud or by calling the API for querying VPCs.
    • networkID: network ID of a subnet in a VPC, which can be obtained on the Virtual Private Cloud page or by calling the API for querying subnets.
    • subnetID: ID of a subnet in a VPC, which can be obtained on the Virtual Private Cloud page or by calling the API for querying subnets.

  3. Call the API described in Creating a Deployment to create an Nginx workload.

    In this example, a workload whose name is nginx and specifications are set to 0.25 vCPUs and 1 GB of memory is to be created from the open source image nginx:latest. After the API is called, CCI creates a container running nginx.

    {
        "apiVersion": "apps/v1",
        "kind": "Deployment",
        "metadata": {
            "name": "nginx"
        },
        "spec": {
            "replicas": 1,
            "selector": {
                "matchLabels": {
                    "app": "nginx"
                }
            },
            "template": {
                "metadata": {
                    "labels": {
                        "app": "nginx"
                    }
                },
                "spec": {
                    "containers": [
                        {
                            "image": "nginx:latest",
                            "name": "container-0",
                            "resources": {
                                "limits": {
                                    "cpu": "250m",
                                    "memory": "1Gi"
                                },
                                "requests": {
                                    "cpu": "250m",
                                    "memory": "1Gi"
                                }
                            }
                        }
                    ],
                    "imagePullSecrets": [
                        {
                            "name": "imagepull-secret"
                        }
                    ]
                }
            }
        }
    }

    You must specify the following parameters:

    • name: Deployment name.
    • replicas: pod quantity, that is, the number of pods under the Deployment.
    • selector.matchLabels: labels that are used by the Deployment to select pods. In this example, app is set to nginx under labels. The pod that has such a label will be selected by the Deployment.
    • template: pod template, which defines pod configurations and specifications.
      • metadata.labels: pod label.
      • spec.containers: definition of a container in the pod.
        • image: image used to create a container.
        • resources.limits: resource limit for a container, that is, the maximum number of resources that a container can use.
        • resources.requests: resource quantity requested by a container.

    After the Nginx workload is created, you can view it on the CCI console.

    Figure 1 nginx