Home > Net >  How to deploy Stale Pod (I mean non operational) through gitlab CI?
How to deploy Stale Pod (I mean non operational) through gitlab CI?

Time:10-24

I would like to deploy an application and the pod should not go to running status(it should be non-operational). User might trigger this when it really requires using Infrastructure as Code (Terraform). I am aware of using kubectl scale -- replicas=0 . Any other leads or info will be well appreciated.

CodePudding user response:

You can keep the replica count to zero for the Deployment or POD into your YAML file if you are using it.

Or if you are using the Terraform

resource "kubernetes_deployment" "example" {
  metadata {
    name = "terraform-example"
    labels = {
      test = "MyExampleApp"
    }
  }

  spec {
    replicas = 0

    selector {
      match_labels = {
        test = "MyExampleApp"
      }
    }

    template {
      metadata {
        labels = {
          test = "MyExampleApp"
        }
      }

      spec {
        container {
          image = "nginx:1.7.8"
          name  = "example"

          resources {
            limits = {
              cpu    = "0.5"
              memory = "512Mi"
            }
            requests = {
              cpu    = "250m"
              memory = "50Mi"
            }
          }

          liveness_probe {
            http_get {
              path = "/nginx_status"
              port = 80

              http_header {
                name  = "X-Custom-Header"
                value = "Awesome"
              }
            }

            initial_delay_seconds = 3
            period_seconds        = 3
          }
        }
      }
    }
  }
}

There is no other way around you can use the client of Kubernetes to do this if don't want to use the Terraform.

If you want to edit the local file using the terraform checkout local-exec

This invokes a process on the machine running Terraform, not on the resource.

resource "aws_instance" "web" {
  # ...

  provisioner "local-exec" {
    command = "echo ${self.private_ip} >> private_ips.txt"
  }
}

using sed command in local-exec or any other command you can update the YAML and apply it.

https://www.terraform.io/docs/language/resources/provisioners/local-exec.html

  • Related