Initcontainer command in kubernetes challange 1 is erring out

No matter how I write the initContainer command in Kubernetes challange 1, I see the task as incomplete.

Here is my POD configuration.

apiVersion: v1
kind: Pod
metadata:
name: jekyll
labels:
run: jekyll
spec:
initContainers:

  • name: copy-jekyll-site
    image: kodekloud/jekyll
    command: [‘sh’, ‘-c’, “jekyll new /site”]
    volumeMounts:
    • name: site
      mountPath: /site
      containers:
  • name: jekyll
    image: kodekloud/jekyll-serve
    volumeMounts:
    • name: site
      mountPath: /site
      volumes:
    • name: site
      persistentVolumeClaim:
      claimName: jekyll-site

I tried with command: [ “jekyll”, “new”, “/site”]. That too was not accepted. Where am I going wrong?

Hi @venumadhav.hari
You add container information inside initContainers base on the YAML file you provide. The right syntax should be :

apiVersion: v1
kind: Pod
metadata:
  namespace: development
  name: jekyll
  labels:
    run: jekyll
spec: 
  containers:
  - name: jekyll
    image: kodekloud/jekyll-serve
    volumeMounts:
    - mountPath: /site
      name: site  
  initContainers:
  - name: copy-jekyll-site
    image: kodekloud/jekyll
    command: [ "jekyll", "new", "/site" ]
    volumeMounts:
    - mountPath: /site
      name: site
  volumes:
  - name: site
    persistentVolumeClaim:
      claimName: jekyll-site

You need to create a block container

Regard

Hi @mmkmou,
Thanks for the reply.
The error in my Yaml was a copy paste indentation error.

However, I have tried the same exact way that you have mentioned in your yaml. But still I got the same error.

Thanks,
Venu

Hi @venumadhav.hari,
Can you please provide us the copy - paste of your error?

I have the same issue, I have all task green except for the pod and the only issue is the command

apiVersion: v1
kind: Pod
metadata:
  name: jekyll
  namespace: development
  labels:
    run: jekyll
spec:
  containers:
  - name: jekyll
    image: kodekloud/jekyll-serve
    volumeMounts:
    - name: site
      mountPath: /site
  initContainers:
  - name: copy-jekyll-site
    image: kodekloud/jekyll
    command: [ "jekyll", "new", "/site" ]
    volumeMounts:
    - name: site
      mountPath: /site
  volumes:
    - name: site
      persistentVolumeClaim:
        claimName: jekyll-site

Thanks

Hi @deanholmes @venumadhav.hari

Just tested the challenge and its work fine

Then I’m more confused.
Any ideas?

Please try again and be sure that the pod is running

Hi,

I now have multiple attempts at this, the pod is running but I still get the x at the command

kubectl get pods jekyll -n development
NAME     READY   STATUS    RESTARTS   AGE
jekyll   1/1     Running   0          80s
kubectl describe pod jekyll -n development
Name:         jekyll
Namespace:    development
Priority:     0
Node:         node01/192.30.252.9
Start Time:   Wed, 17 May 2023 17:19:44 +0000
Labels:       run=jekyll
Annotations:  <none>
Status:       Running
IP:           10.244.192.2
IPs:
  IP:  10.244.192.2
Init Containers:
  copy-jekyll-site:
    Container ID:  docker://b3721a13581ebebf5dd4ed04e71edfe015de61fb92c1ee3106b1e54b4a820ec7
    Image:         kodekloud/jekyll
    Image ID:      docker-pullable://kodekloud/jekyll@sha256:e7776dd75bf813e7da2e76badecd9bfadf1e7893fe0d588cc552ea090594e00f
    Port:          <none>
    Host Port:     <none>
    Command:
      jekyll
      new
      /site
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 17 May 2023 17:20:02 +0000
      Finished:     Wed, 17 May 2023 17:20:17 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /site from site (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-l6tl7 (ro)
Containers:
  jekyll:
    Container ID:   docker://2b49d80158db4576690a5bc9964724b0d0845688e40c1fbbbe56e18e058a822f
    Image:          kodekloud/jekyll-serve
    Image ID:       docker-pullable://kodekloud/jekyll-serve@sha256:5e2be6d03d137e9a724624118b2567931aff94e33ae9dabed34dc2626772e8be
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Wed, 17 May 2023 17:20:19 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /site from site (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-l6tl7 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  site:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  jekyll-site
    ReadOnly:   false
  kube-api-access-l6tl7:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  44s   default-scheduler  Successfully assigned development/jekyll to node01
  Normal  Pulling    43s   kubelet            Pulling image "kodekloud/jekyll"
  Normal  Pulled     27s   kubelet            Successfully pulled image "kodekloud/jekyll" in 15.308893949s
  Normal  Created    27s   kubelet            Created container copy-jekyll-site
  Normal  Started    26s   kubelet            Started container copy-jekyll-site
  Normal  Pulling    10s   kubelet            Pulling image "kodekloud/jekyll-serve"
  Normal  Pulled     9s    kubelet            Successfully pulled image "kodekloud/jekyll-serve" in 904.162511ms
  Normal  Created    9s    kubelet            Created container jekyll
  Normal  Started    9s    kubelet            Started container jekyll

Thanks
Dean

I don’t know what I did different but it finally completed, it might be a timing thing, giving it enough time to complete the command
I’m going to run it a few more times just to practice

Thanks
Dean

1 Like

The issue is the git lab code. if you directly copypaste or clone the gitlab , then that code will give issue of command run and init container not running.
After multiple tries , finally create a dummy pod using --dry-run=client and saving it to yaml file.

k run pod --image gcr.io/kodekloud/customimage/jekyll-serve -l run=jekyll -n development --dry-run=client -o yaml > jekyll_pod.yaml

after that editing the file to add line by line all stuff.
make sure you type everything and use proper indentation.
after completing file, you will notice no change from gitlab file but still this will not give error coz we typed and not copy pasted.

vi jekyll_pod.yaml
rm -rf /site

controlplane ~ ➜ cat jekyll_pod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: jekyll
name: jekyll
namespace: development
spec:
containers:

controlplane ~ ➜

controlplane ~ ➜ k create -f jekyll_pod.yaml
pod/jekyll created

controlplane ~ ➜ k get pods -n development jekyll --watch
NAME READY STATUS RESTARTS AGE
jekyll 0/1 Init:0/1 0 17s
jekyll 0/1 Init:0/1 0 18s
jekyll 0/1 PodInitializing 0 110s
jekyll 1/1 Running 0 111s
^C
controlplane ~ :heavy_multiplication_x: k get pod
NAME READY STATUS RESTARTS AGE
jekyll 1/1 Running 0 2m49s