Stateless applications are applications that do not use the persistent storage of a user 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 user cluster, ensure you have the following resources:
Locate the user cluster name, or ask your Platform Administrator what the cluster name is.
Sign in and generate the kubeconfig file for the user cluster if you don't have one.
Use the kubeconfig path of the user cluster to replace
USER_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.
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 USER_CLUSTER_KUBECONFIG \
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:
USER_CLUSTER_KUBECONFIG
: the kubeconfig file for the user cluster to which you're deploying container workloads.DEPLOYMENT_NAME
: the kubeconfig file for the user 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 replicatedPod
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 asREGISTRY_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
You can also use kubectl apply -f DIRECTORY
to create new
objects defined by manifest files stored in a directory.