0

Goal - Deploy Graylog environment with Elasticsearch and Mongodb. 1 pod each of graylog and mongo and 2 pods of ES.

Currently, I am trying to deploy mongodb as task and a service. I have written a script for the same, but it does not work as it is supposed to.

(EDITED)

Some more info regarding my Kubernetes cluster -

  • Kubernetes cluster is running on a cloud server. I connect from my local machine using kubectl command to fetch and perform basic operations. (Copied kubeconfig file to my local machine for the connection)
  • I have installed tekton cli on my local machine.

Current Scenario - I have created a task and a deployment script for my mongo-deployment.

Here is my simple deployment script - mongo-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-deploy
  labels:
    service: mongo-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      service: mongo-deploy
  template:
    metadata:
      labels:
        service: mongo-deploy
    spec:
      containers:
      - name: mongodb
        image: mongo:4.2
        ports:
        - containerPort: 27017

---
apiVersion: v1
kind: Service
metadata:
  name: mongo
spec:
  selector:
    service: mongo-deploy
  ports:
  - name: "27017"
    port: 27017
    targetPort: 27017

Here is my task-script - task-mongo-deploy.yaml

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: mongo-deploy
spec:
  steps:
    - name: mongo-deploy
      image: mongo:4.2
      command: [echo -----------------------------------]
      args:
        - |-
          kubectl apply -f /path-to-location/tekton-scripts/mongo-deploy.yaml
          echo -----------------------------------

Steps I performed -

  1. kubectl apply -f task-mongo-deploy.yaml
  2. tkn task start mongo-deploy
  3. Here is my output -
$ tkn task start mongo-deploy
TaskRun started: mongo-deploy-run-mdblw

In order to track the TaskRun progress run:
tkn taskrun logs mongo-deploy-run-mdblw -f -n default
$ tkn taskrun logs mongo-deploy-run-mdblw -f -n default
task mongo-deploy has failed: "step-mongo-deploy" exited with code 1 (image: "docker-pullable://mongo@sha256:5c3059c8191861aaf766ce1ac592ebb42ea71ff13951701049bca93e8d614f96"); for logs run: kubectl -n default logs mongo-deploy-run-mdblw-pod-6fgkc -c step-mongo-deploy

[mongo-deploy] 2021/06/04 14:53:37 Error executing command: exec: "echo -----------------------------------": executable file not found in $PATH

container step-mongo-deploy has failed  : [{"key":"StartedAt","value":"2021-06-04T14:53:37.297Z","type":"InternalTektonResult"}]

It is still not running. Any idea where I went wrong?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Shresth Suman
  • 29
  • 1
  • 6
  • What are you trying to do? Why do you have a database as a step in the Task? Steps in a Task are typically _commands_ e.g. `kubectl apply` – Jonas Jun 02 '21 at 16:09
  • Hi @Jonas, thanks for your reply. Now as I understand, I can use typical commands in the steps. However, I am still unable to run it. Do find any error in my approach? – Shresth Suman Jun 04 '21 at 15:15
  • I don’t understand your approach. – Jonas Jun 04 '21 at 18:03

1 Answers1

0

You are creating a Task "mongo-deploy" that is using kubectl to deploy an application to the cluster. For this task to work properly, it need an image that contains the kubectl tool - you don't need a mongodb-image in the Task, it is only using kubectl.

Jonas
  • 121,568
  • 97
  • 310
  • 388