Kubernetes Sidecar Containers - lab seems to have issues

@Tej-Singh-Rana @rahul456 I am getting this strange error complaining about the name of the container.

thor@jump_host /$ kubectl apply -f webserver.yml
The Pod “webserver” is invalid:

  • spec.containers[0].name: Invalid value: “nginx-container\u00a0”: a DNS-1123 label must consist of lower case alphanumeric characters or ‘-’, and must start and end with an alphanumeric character (e.g. ‘my-name’, or ‘123-abc’, regex used for validation is’a-z0-9?’)
  • spec.containers[1].name: Invalid value: “sidecar-container\u00a0”: a DNS-1123 labelmust consist of lower case alphanumeric characters or ‘-’, and must start and end with an alphanumeric character (e.g. ‘my-name’, or ‘123-abc’, regex used for validation is ‘a-z0-9?’)

These are the spec of my two containers:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: webserver
  name: webserver
spec:
  volumes:
    - name: shared-logs
      emptyDir: {}
  containers:
  - name: nginx-container 
    image: nginx:latest
    volumeMounts:
    - name: shared-logs
      mountPath: /usr/share/nginx/html
  - name: sidecar-container 
    image: ubuntu:latest
    command: ["/bin/sh"]
    args: ["-c", "while true; do (mycommand); sleep 30; done"]
    volumeMounts:
    - name: shared-logs
      mountPath: /var/log/nginx 
  1. Create a pod named webserver.
  2. Create an emptyDir volumemount name: shared-logs.
  3. Create two containers from nginx and ubuntu images with latest tag only and remember to mention tag i.e nginx:latest, nginx container name should be nginx-container and ubuntu container name should be sidecar-container on webserver pod.
  4. Add command on sidecar-container “sh”,“-c”,“while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done”
  5. Mount volume /var/log/nginx on both containers, all containers should be up and running.
    Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
1 Like

Hello, nashwan
You defined volumeMounts but not defined volumes for that.

@Tej-Singh-Rana my concern is this error:
The Pod “webserver” is invalid:

  • spec.containers[0].name: Invalid value: “nginx-container\u00a0”: a DNS-1123 label must consist of lower case alphanumeric characters or ‘-’, and must start and end with an alphanumeric character (e.g. ‘my-name’, or ‘123-abc’, regex used for validation is’a-z0-9?')

what is causing this, that is where I ma stucked.

Actually it avoids different name syntax scenario except this rules.

But your yaml is working fine. I don’t know where you were getting this errors.

yeah that is were I am really confused. not sure if the lab has issues or what is causing this:
@Inderpreet @rahul456 any idea what is wrong here?

Can you rerun this yaml and share error image?

@Tej-Singh-Rana
same error
thor@jump_host /$ kubectl apply -f webserver.yml
The Pod “webserver” is invalid:

  • spec.containers[0].name: Invalid value: “nginx-container\u00a0”: a DNS-1123 label must consist of lower case alphanumeric characters or ‘-’, and must start and end with an alphanumeric character (e.g. ‘my-name’, or ‘123-abc’, regex used for validation is’a-z0-9?')
  • spec.containers[1].name: Invalid value: “sidecar-container\u00a0”: a DNS-1123 labelmust consist of lower case alphanumeric characters or ‘-’, and must start and end with an alphanumeric character (e.g. ‘my-name’, or ‘123-abc’, regex used for validation is ‘a-z0-9?’)

Show me an image don’t do copy paste.

I can’t upload images, my laptops is restricted. I am copying and pasting what I get on the screen what is the different :smile:
every time if I need to upload photo, will take me 15 mins, have to take a photo using my mobile, send it then share it from there.

In your yaml file which one you shared. I haven’t seen name nginx-container and sidecar-container name. I don’t know from where you are getting this.
Then don’t do, if it will take time.

@player001
yeah that is just a sample yaml file, I dont want to share the actual yaml file perhaps would be a breach of rule, not sure (here is the actual one without command)

apiVersion: v1
kind: Pod
metadata:
  name: webserver
spec:
  containers:
  - name: nginx-container 
    image: nginx:latest
    volumeMounts:
    - name: shared-logs
      mountPath: /usr/share/nginx/html
  - name: sidecar-container 
    image: ubuntu:latest
    command: ["/bin/sh"]
    args: ["-c", "while true; do (command) sleep 30;done"]
    volumeMounts:
    - name: shared-logs
      mountPath: /var/log/nginx 
  
dnsPolicy: Default
  volumes:
  - name: shared-logs
    emptyDir: {}

by the way here is the question for this task:

  1. Create a pod named webserver.
  2. Create an emptyDir volumemount name: shared-logs.
  3. Create two containers from nginx and ubuntu images with latest tag only and remember to mention tag i.e nginx:latest, nginx container name should be nginx-container and ubuntu container name should be sidecar-container on webserver pod.
  4. Add command on sidecar-container “sh”,“-c”,“while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done”
  5. Mount volume /var/log/nginx on both containers, all containers should be up and running.
    Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

It’s up and running. I just added full command.

I ran this yaml file on my own lab, its all good, I dont know what is happening on this lab. I keep getting this error.
where did you try this? on your own lab?

Obviously Yes. :100:

Tag to KKE support they will check.

there we go, then this lab has some issues. who we should contact, my requests and call outs never been responded by kodekloud team. @Ayman @kodekloud-support3 @rahul456 @mmumshad @Inderpreet @Devops

@nashwan can you please message me your original yaml ?

@Inderpreet
messaged you the yml file I am using for this task.

Hello @Inderpreet @rahul456 @kodekloud-support3
Two feedbacks on this task perhaps would be applied on all other kubernetes tasks:

  1. There was one whitespacing at the end of the containers image name that causes that issue, which is more specific to kodekloud validation tool, but not the actual kubernetes validation. I was able to run same yaml file on my gke with no issues.

  2. The command given here can be excuted in different ways. But again kodekloud validation tool seems only to accept one way even though if your containers are running.

Please check my tasks and if possible reassign it to me because i have done it absolutely right.

I would love to see your feedback on my answers.

Thank you

1 Like