Deployments are workloads (for example, Nginx) that do not store any data or status. You can create Deployments on the CCE console or by running kubectl commands.
If a pod has multiple containers, ensure that the ports used by the containers do not conflict with each other. Otherwise, creating the Deployment will fail.
If the workload contains more than one pod, EVS volumes cannot be mounted.
Service Settings
A Service is used for pod access. With a fixed IP address, a Service forwards access traffic to pods and performs load balancing for these pods.
You can also create a Service after creating a workload. For details about the Service, see Service Overview.
The following procedure uses Nginx as an example to describe how to create a workload using kubectl.
vi nginx-deployment.yaml
The following is an example YAML file. For more information about Deployments, see Kubernetes documentation.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx strategy: type: RollingUpdate template: metadata: labels: app: nginx spec: containers: - image: nginx # If you use an image in My Images, obtain the image path from SWR. imagePullPolicy: Always name: nginx imagePullSecrets: - name: default-secret
For details about these parameters, see Table 1.
Parameter |
Description |
Mandatory/Optional |
---|---|---|
apiVersion |
API version. NOTE:
Set this parameter based on the cluster version.
|
Mandatory |
kind |
Type of a created object. |
Mandatory |
metadata |
Metadata of a resource object. |
Mandatory |
name |
Name of the Deployment. |
Mandatory |
Spec |
Detailed description of the Deployment. |
Mandatory |
replicas |
Number of pods. |
Mandatory |
selector |
Determines container pods that can be managed by the Deployment. |
Mandatory |
strategy |
Upgrade mode. Possible values:
By default, rolling update is used. |
Optional |
template |
Detailed description of a created container pod. |
Mandatory |
metadata |
Metadata. |
Mandatory |
labels |
metadata.labels: Container labels. |
Optional |
spec: containers |
|
Mandatory |
imagePullSecrets |
Name of the secret used during image pulling. If a private image is used, this parameter is mandatory.
|
Optional |
kubectl create -f nginx-deployment.yaml
If the following information is displayed, the Deployment is being created.
deployment "nginx" created
kubectl get deployment
If the following information is displayed, the Deployment is running.
NAME READY UP-TO-DATE AVAILABLE AGE nginx 1/1 1 1 4m5s
Parameter description