2 minutes to read - Apr 12, 2023

Write Kubernetes deployment file

What is wrong in Kubernetes deployment file? apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: web spec: selector: matchLabels: app: web replicas: 5 strategy: type: RollingUpdate template: metadata: labels: spec: containers: —name: nginx image: nginx ports: —containerPort: 80

There are a few issues with the deployment file that you have provided:

1. The `template` section is missing a `labels` field. This field is required to specify the labels that are applied to the pods created by the deployment.

2. The `containers` field is missing a hyphen at the beginning of the line. It should be written as `- name: nginx` instead of `—name: nginx`.

3. The `ports` field is missing a hyphen at the beginning of the line. It should be written as `- containerPort: 80` instead of `—containerPort: 80`.

4. The `image` field is missing the image tag. It should be written as `image: nginx:` instead of just `image: nginx`.

Here's the corrected deployment file:

Copy code

`apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: web spec: selector: matchLabels: app: web replicas: 5 strategy: type: RollingUpdate template: metadata: labels: app: web spec: containers: - name: nginx image: nginx: ports: - containerPort: 80`

loading...