Getting an error during this tasks execution

Ques:

Create a namespace iron-namespace-datacenter

Create a deployment iron-gallery-deployment-datacenter for iron gallery under the same namespace you created.

:- Labels run should be iron-gallery.

:- Replicas count should be 1.

:- Selector’s matchLabels run should be iron-gallery.

:- Template labels run should be iron-gallery under metadata.

:- The container should be named as iron-gallery-container-datacenter, use kodekloud/irongallery:2.0 image ( use exact image name / tag ).

:- Resources limits for memory should be 100Mi and for CPU should be 50m.

:- First volumeMount name should be config, its mountPath should be /usr/share/nginx/html/data.

:- Second volumeMount name should be images, its mountPath should be /usr/share/nginx/html/uploads.

:- First volume name should be config and give it emptyDir and second volume name should be images, also give it emptyDir.

Create a deployment iron-db-deployment-datacenter for iron db under the same namespace.

:- Labels db should be mariadb.

:- Replicas count should be 1.

:- Selector’s matchLabels db should be mariadb.

:- Template labels db should be mariadb under metadata.

:- The container name should be iron-db-container-datacenter, use kodekloud/irondb:2.0 image ( use exact image name / tag ).

:- Define environment, set MYSQL_DATABASE its value should be database_blog, set MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD value should be with some complex passwords for DB connections, and MYSQL_USER value should be any custom user ( except root ).

:- Volume mount name should be db and its mountPath should be /var/lib/mysql. Volume name should be db and give it an emptyDir.

Create a service for iron db which should be named iron-db-service-datacenter under the same namespace. Configure spec as selector’s db should be mariadb. Protocol should be TCP, port and targetPort should be 3306 and its type should be ClusterIP.

Create a service for iron gallery which should be named iron-gallery-service-datacenter under the same namespace. Configure spec as selector’s run should be iron-gallery. Protocol should be TCP, port and targetPort should be 80, nodePort should be 32678 and its type should be NodePort.

Note:

We don’t need to make connection b/w database and front-end now, if the installation page is coming up it should be enough for now.

The kubectl on jump_host has been configured to work with the kubernetes cluster.

Answer:

thor@jumphost ~$ cat iron-gallery-deployment-xfusion.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: iron-gallery
name: iron-gallery-deployment-xfusion
namespace: iron-namespace-xfusion
spec:
replicas: 1
selector:
matchLabels:
run: iron-gallery
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: iron-gallery
spec:
containers:
- image: kodekloud/irongallery:2.0
name: iron-gallery-container-xfusion
resources:
limits:
memory: “100Mi”
cpu: “50m”
volumeMounts:
- name: config
mountPath: “/usr/share/nginx/html/data”
volumeMounts:
- name: images
mountPath: “/usr/share/nginx/html/uploads”
volumes:
- name: config
emptyDir:
volumes:
- name: images
emptyDir:

#################################################################

thor@jumphost ~$ cat iron-db-deployment-xfusion.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
db: mariadb
name: iron-db-deployment-xfusion
namespace: iron-namespace-xfusion
spec:
replicas: 1
selector:
matchLabels:
db: mariadb
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
db: mariadb
spec:
containers:
- image: kodekloud/irondb:2.0
name: iron-db-container-xfusion
env:
- name: MYSQL_DATABASE
value: database_web
- name: MYSQL_ROOT_PASSWORD
value: Algeria@321
- name: MYSQL_PASSWORD
value: Algeria@321
- name: MYSQL_USER
value: udhaya
volumeMounts:
- name: db
mountPath: /var/lib/mysql
volumes:
- name: db
emptyDir: {}

#################################################################

thor@jumphost ~$ cat iron-db-service-xfusion.yaml
apiVersion: v1
kind: Service
metadata:
name: iron-db-service-xfusion
namespace: iron-namespace-xfusion
spec:
ports:

  • name: iron-db-service-xfusion
    port: 3306
    protocol: TCP
    targetPort: 3306
    selector:
    db: mariadb
    type: ClusterIP
    status:
    loadBalancer: {}
    #################################################################

thor@jumphost ~$ cat iron-gallery-service-xfusion.yaml
apiVersion: v1
kind: Service
metadata:
name: iron-gallery-service-xfusion
namespace: iron-namespace-xfusion
spec:
ports:

  • name: iron-gallery-service-xfusion
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 32678
    selector:
    run: iron-gallery
    type: NodePort
    status:
    loadBalancer: {}

Hello,

Kindly paste YAML as

code blocks

Press the </> button above the text box to start a code block.

All the stuff above has lost its indentation and there’s no way of telling if it is correct

Thank you for your prompt response.

Ques:

Create a namespace iron-namespace-datacenter

Create a deployment iron-gallery-deployment-datacenter for iron gallery under the same namespace you created.

:- Labels run should be iron-gallery.

:- Replicas count should be 1.

:- Selector’s matchLabels run should be iron-gallery.

:- Template labels run should be iron-gallery under metadata.

:- The container should be named as iron-gallery-container-datacenter, use kodekloud/irongallery:2.0 image ( use exact image name / tag ).

:- Resources limits for memory should be 100Mi and for CPU should be 50m.

:- First volumeMount name should be config, its mountPath should be /usr/share/nginx/html/data.

:- Second volumeMount name should be images, its mountPath should be /usr/share/nginx/html/uploads.

:- First volume name should be config and give it emptyDir and second volume name should be images, also give it emptyDir.

Create a deployment iron-db-deployment-datacenter for iron db under the same namespace.

:- Labels db should be mariadb.

:- Replicas count should be 1.

:- Selector’s matchLabels db should be mariadb.

:- Template labels db should be mariadb under metadata.

:- The container name should be iron-db-container-datacenter, use kodekloud/irondb:2.0 image ( use exact image name / tag ).

:- Define environment, set MYSQL_DATABASE its value should be database_blog, set MYSQL_ROOT_PASSWORD and MYSQL_PASSWORD value should be with some complex passwords for DB connections, and MYSQL_USER value should be any custom user ( except root ).

:- Volume mount name should be db and its mountPath should be /var/lib/mysql. Volume name should be db and give it an emptyDir.

Create a service for iron db which should be named iron-db-service-datacenter under the same namespace. Configure spec as selector’s db should be mariadb. Protocol should be TCP, port and targetPort should be 3306 and its type should be ClusterIP.

Create a service for iron gallery which should be named iron-gallery-service-datacenter under the same namespace. Configure spec as selector’s run should be iron-gallery. Protocol should be TCP, port and targetPort should be 80, nodePort should be 32678 and its type should be NodePort.

Note:

We don’t need to make connection b/w database and front-end now, if the installation page is coming up it should be enough for now.

The kubectl on jump_host has been configured to work with the kubernetes cluster.

What I have prepared for this Ques:

thor@jumphost ~$ cat iron-gallery-deployment-xfusion.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: iron-gallery
  name: iron-gallery-deployment-xfusion
  namespace: iron-namespace-xfusion
spec:
  replicas: 1
  selector:
    matchLabels:
      run: iron-gallery
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: iron-gallery
    spec:
      containers:
      - image: kodekloud/irongallery:2.0
        name: iron-gallery-container-xfusion
        resources:
          limits:
            memory: "100Mi"
            cpu: "50m"
        volumeMounts:
        - name: config
          mountPath: "/usr/share/nginx/html/data"
        volumeMounts:
        - name: images
          mountPath: "/usr/share/nginx/html/uploads"
      volumes:
        - name: config 
          emptyDir:
      volumes: 
        - name: images
          emptyDir:

#################################################################

thor@jumphost ~$ cat iron-db-deployment-xfusion.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    db: mariadb
  name: iron-db-deployment-xfusion
  namespace: iron-namespace-xfusion
spec:
  replicas: 1
  selector:
    matchLabels:
      db: mariadb
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        db: mariadb
    spec:
      containers:
      - image: kodekloud/irondb:2.0
        name: iron-db-container-xfusion
        env:
          - name: MYSQL_DATABASE
            value: database_web
          - name: MYSQL_ROOT_PASSWORD
            value: Algeria@321
          - name: MYSQL_PASSWORD
            value: Algeria@321
          - name: MYSQL_USER
            value: udhaya
        volumeMounts:
          - name: db
            mountPath: /var/lib/mysql
      volumes:
        - name: db
          emptyDir: {}

#################################################################

thor@jumphost ~$ cat iron-db-service-xfusion.yaml

apiVersion: v1
kind: Service
metadata:
  name: iron-db-service-xfusion
  namespace: iron-namespace-xfusion
spec:
  ports:
  - name: iron-db-service-xfusion
    port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    db: mariadb
  type: ClusterIP
status:
  loadBalancer: {}

#################################################################

thor@jumphost ~$ cat iron-gallery-service-xfusion.yaml

apiVersion: v1
kind: Service
metadata:
  name: iron-gallery-service-xfusion
  namespace: iron-namespace-xfusion
spec:
  ports:
  - name: iron-gallery-service-xfusion
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 32678
  selector:
    run: iron-gallery
  type: NodePort
status:
  loadBalancer: {}

Please refer to Deploy Iron Gallery App on Kubernetes task fails - #2 by Alistair_KodeKloud where I solved this for someone else

Hi
I have tried twise the task with the shared link but unfortunately the error is still persist.

Note: Changed the values according to the Questions

I just re-tried it and it worked for me.

However I can see an error here in what you posted above…

and it will cause the errors you are seeing about volumes and mounts

Compare my solution in the other post with yours here in respect of volumes and mounts, note the difference and understand what causes the issue.

Hint - apply your pod manifest as you wrote it, then get the pod back with -o yaml. Look at the volumes and mounts from the running pod. What do you notice?

I found only this difference from your solution:

volumeMounts:
        - mountPath: /usr/share/nginx/html/data
          name: config
        - mountPath: /usr/share/nginx/html/uploads
          name: images
This is from my old yaml file:

 volumeMounts:
        - name: config
          mountPath: "/usr/share/nginx/html/data"
        volumeMounts:
        - name: images
          mountPath: "/usr/share/nginx/html/uploads"

If that is only the issue now i changed and its working fine.

Thank you for your valuable time to analyse this and share your input.

That is the issue.

You cannot declare volumes or volumeMounts, or for that that matter any key twice.

What is expected is a list of volumes or mounts, not two separate declarations of a single volume or mount.

If you had got the pod back as you have defined it after deploying using -o yaml this is what you would have seen - and what the marking script did see (from spec section onwards)

  spec:
      containers:
      - image: kodekloud/irongallery:2.0
        name: iron-gallery-container-xfusion
        resources:
          limits:
            memory: "100Mi"
            cpu: "50m"
        volumeMounts:
        - name: images
          mountPath: "/usr/share/nginx/html/uploads"
      volumes: 
        - name: images
          emptyDir:

which is why it was complaining you had errors there, because you duplicated the keys volumes and volumeMounts, eliminating the two config entries completely!