Since a Deployment manages the ReplicaSet, which, in turn, manages the Pods, the Deployment manifest is very similar to the ReplicaSet manifest. However, the Deployment manifest uses Deployment-specific fields and objects, for example, the strategy object.
12345678910111213141516171819
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kyma
spec:
replicas: 3
selector:
matchLabels:
app: hello-kyma
template: # Pod template
metadata:
labels:
app: hello-kyma
spec:
containers:
- name: hello-kyma
image: ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0
ports:
- containerPort: 8080
This example shows a Deployment manifest with the name hello-kyma.
The Deployment has three replicas and the Pod template uses the label app: hello-kyma. The Pod template has a container with the name hello-kyma and the image hello-kyma:1.0.0 pulled from the GitHub Container Registry (ghcr.io). The container exposes the port: 8080.
Let's have a look at the Deployment manifest's spec section in detail:.
The Deployment spec section in detail
| Field | Description | Required | Possible values |
|---|
| Replicas | The number of replicas of the application. | Yes | Integer |
| Selector | The selector to identify the Pods managed by the Deployment. | Yes | At least a subset of the labels defined in the Pod template. |
| Template | The Pod template used to create the Pods managed by the Deployment. | Yes | Pod labels and Pod manifest. |
If you want to pull the image from a private registry, you can do so by providing the credentials in the Deployment manifest's spec.template.spec field:
12345678910111213
...
spec:
...
template:
...
spec:
imagePullSecrets:
- name: myregistrykey
containers:
- name: hello-kyma
image: ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0
ports:
- containerPort: 8080
Concerning the containers object of the Pod template, the following attributes are recommended:
Recommended attributes in the containers object
| Field | Description | Required | Possible values |
|---|
| Name | The name of the container. | Yes | String |
| Image | The image of the container. | Yes | String |
| Resources | The resources of the container. | No | Resource requirements |
| ImagePullPolicy | The image pull policy. | No | Always, IfNotPresent, Never |
| Ports | The container's ports. | No | Container ports |
The ImagePullPolicy is set to IfNotPresent by default. This means that the image is pulled only if it is not present locally on the cluster node. If you want to always pull the image, you can set the ImagePullPolicy to Always.
Note
If you specify an image with the latest tag and you or the system create a new Pod, Kubernetes always downloads the most recent latest version. This can lead to unexpected behavior since other Pods can still use the old image. Therefore, it is recommended to use a specific version of the image, for example, hello-kyma:1.0.0.
See an example Deployment manifest:
1234567891011121314151617181920212223242526272829
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kyma
labels:
app.kubernetes.io/name: hello-kyma
spec:
replicas: 3
selector:
matchLabels:
app: hello-kyma
template:
metadata:
labels:
app: hello-kyma
spec:
imagePullSecrets: [ ]
containers:
- name: hello-kyma
image: 'ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0'
resources:
requests:
memory: 64Mi # 64MiB (2^26 bytes)
cpu: 50m # 50 millicores (1/20th of a core), 500m = 0.5 cores
limits:
memory: 128Mi
cpu: 100m # 100 millicores (1/10th of a core), 1000m = 1 core
ports:
- containerPort: 8080
For all other fields, see the Kubernetes Deployment documentation.