Kubernetes level 1 - challenge 5 problem

Hello,

I have this code :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 6
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:

    spec:
      containers:
        - name: nginx
          image: nginx:1.17

but I get this errror messages :slight_smile:

The Deployment "nginx-deployment" is invalid: 
* spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`
* spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"nginx"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

anyone who can help me to solve this ?

Hello,you need to add the “Label” under the “metadata”,it would look like this:
metadata:
labels:
app: nginx

The pod label should be matching the Deployment’s :slight_smile:

I tried that and saw this message :

thor@jumphost ~$ k apply -f limits.yaml
The Deployment "nginx-deployment" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"nginx"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Try adding labels to the metadata:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx

Can you provide the entire task so we can examine it?

of course

An application currently running on the Kubernetes cluster employs the nginx web server. The Nautilus application development team has introduced some recent changes that need deployment. They've crafted an image nginx:1.19 with the latest updates.

Execute a rolling update for this application, integrating the nginx:1.19 image. The deployment is named nginx-deployment.

Ensure all pods are operational post-update.

Note: The kubectl utility on jump_host is set up to operate with the Kubernetes cluster

Hello,i think there is a mistake in this Deployment manifest file,it should be like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-name
labels: deployment-label
spec:
replicas: x
selector:
matchLabels:

template:
metadata:
name: pod-name
labels:
<pod-label,this should match the “matchLabels” defined above>
spec:
containers:

sorry. i m a a little confused.
So matchlabels schould also be empty ?

ah ok,this is assuming we have a Deployment set up already,you need to upgrade the container image into “nginx:1.19”,you can do this command to update a Deployment:
“kubectl edit deployment nginx-deployment”
and then,change the container image into "nginx:1.19,this should upgrade the Deployment.
First,i thought the task is creating one but now i get it :slight_smile:

There is already a Deployment up and running,the task is to change the container image version into “nginx:1.19”,that is it,no need to create a Deployment :slight_smile:

oke
and how to I then make the upgrade ?

go to the section where your container image is,it is supposed to be under “spec”,then update it from nginx:1.17==>nginx:1.19,save the changes and you are good.

nope the lab fails with this as error :

Pod is not 'Running'

did you update the container image accordingly?
because that is all the task about,you update the image version,save the changes and the Deployment should be updated automatically,

Thanks

I had to wait till the pod was running , first time it was still in the creation state

Good Job,now the Deployment is running with nginx:1.19 version,to downgrade the Deployment to its previous state (previous version),simply do “kubectl rollout undo deployment nginx-deployment”==>if you check the nginx image after this,you will notice that the version becomes “nginx:1.17”.

That is the next challenge
Can I check it with the describe part ?

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 6
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
# must match with matchLabels that will by managed by Deployment
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.17