Create stateless workloads

Stateless applications are applications that don't use the persistent storage of a Kubernetes cluster to store data or application state. Instead, data and application state are stored with the client, which makes stateless applications more scalable. For example, for a stateless frontend application, you deploy multiple replicas to increase its availability and scale down when demand is low. In this case, the replicas don't need unique identities.

Before you begin

To run commands against a Kubernetes cluster, ensure you have the following resources:

  1. Locate the Kubernetes cluster name, or ask your Platform Administrator what the cluster name is.

  2. Sign in and generate the kubeconfig file for the Kubernetes cluster if you don't have one.

  3. Use the kubeconfig path of the Kubernetes cluster to replace KUBERNETES_CLUSTER_KUBECONFIG in these instructions.

To get the required permissions to create stateless workloads, ask your Organization IAM Admin to grant you the Namespace Admin role (namespace-admin) in your project namespace.

Create a deployment

You create a deployment by writing a Deployment manifest and running kubectl apply to create the resource. This method also retains updates made to live resources without merging the changes back into the manifest files.

To create a Deployment from its manifest file, run:

kubectl --kubeconfig KUBERNETES_CLUSTER_KUBECONFIG -n NAMESPACE \
    apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: DEPLOYMENT_NAME
spec:
  replicas: NUMBER_OF_REPLICAS
  selector:
    matchLabels:
      run: APP_NAME
  template:
    metadata:
      labels: # The labels given to each pod in the deployment, which are used
              # to manage all pods in the deployment.
        run: APP_NAME
    spec: # The pod specification, which defines how each pod runs in the deployment.
      containers:
      - name: CONTAINER_NAME
        image: CONTAINER_IMAGE
EOF

Replace the following:

  • KUBERNETES_CLUSTER_KUBECONFIG: the kubeconfig file for the Kubernetes cluster to which you're deploying container workloads.

  • NAMESPACE: the project namespace in which to deploy the container workloads.

  • DEPLOYMENT_NAME: the kubeconfig file for the cluster to which you're deploying container workloads.

  • APP_NAME: the name of the application to run within the deployment.

  • NUMBER_OF_REPLICAS: the number of replicated Pod objects that the deployment manages.

  • CONTAINER_NAME: the name of the container.

  • CONTAINER_IMAGE: the name of the container image. You must include the container registry path and version of the image, such as REGISTRY_PATH/hello-app:1.0.

For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      run: my-app
  template:
    metadata:
      labels:
        run: my-app
    spec:
      containers:
      - name: hello-app
        image: REGISTRY_PATH/hello-app:1.0

If you're deploying GPU workloads to your containers, see Manage GPU container workloads for more information.