OCSInventory-NG / OCSInventory-Docker-Stack

Docker stack for OCSInventory Server
GNU General Public License v3.0
42 stars 38 forks source link

Deploy OCS kubernetes #12

Closed jmateusousa closed 3 years ago

jmateusousa commented 3 years ago

It's hard to solve a problem when important details are missing, that why we added this template, to help you and us.

General informations

Docker host's operating system : Linux srv-kube-master-01 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Docker informations

Kubernetes v1.19.3 Docker version : Docker version 19.03.13, build 4484c46d9d image = ocsinventory/ocsinventory-docker-image:latest

Problem's description

Friends, I'm trying to run ocs on kubernetes, however when deploying the container it is active, however I'm getting the error message below. When accessing the link http: //ocs.domain/ocsreports/ I get an HTTP ERROR 500, but when accessing http: //ocs.domain/ the access is ok

log AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.42.0.7. Set the 'ServerName' directive globally to suppress this message

Deploy terraform

provedor para conexão ao kubernetes

terraform {
  required_providers {
    kubernetes = {
      source = "hashicorp/kubernetes"
    }
  }
}

provider "kubernetes" {}

criação do namespace

resource "kubernetes_namespace" "ocsinvetory" {
  metadata {
    annotations = {
      name = "ocsinvetory"
    }
    name = "ocsinvetory"
  }
}

resource "kubernetes_config_map" "ocsinvetory" {
  metadata {
    name = "ocsinvetory-env"
    namespace = "ocsinvetory"
  }
    data = {
      "OCS_DB_NAME" = "ocsweb"
      "OCS_DB_SERVER" = "192.168.250.x"
      "OCS_DB_PORT" = "3306"
      "TZ" = "America/Fortaleza"
    }
}

resource "kubernetes_secret" "ocsinvetory" {
  metadata {
    name = "ocsinvetory-auth"
    namespace = "ocsinvetory"
  }

  data = {
    username = "ocs"
    password = "password"
  }

  type = "kubernetes.io/basic-auth"
}

deploy da aplicação

resource "kubernetes_deployment" "ocsinvetory" {
  metadata {
    name = "ocsinvetory"
    namespace = "ocsinvetory"
    labels = {
      app = "ocsinvetory"
    }
  }

  spec {
    replicas = 3
    selector {
      match_labels = {
        app = "ocsinvetory"
      }
    }

    template {
      metadata {
        labels = {
          app = "ocsinvetory"
        }
      }

      spec {
        hostname = "ocsinvetory"
        container {
          image = "ocsinventory/ocsinventory-docker-image:latest"
          name  = "ocsinvetory-test"
          port {
            name = "http-web"
            container_port = 80
          }
          port {
            name = "https-web"
            container_port = 443
          }
          env {
            name = "TZ"
            value_from {
                config_map_key_ref {
                    name = "ocsinvetory-env"
                    key = "TZ"
                }
            }
          }
          env {
            name = "OCS_DB_NAME"
            value_from {
                config_map_key_ref {
                    name = "ocsinvetory-env"
                    key = "OCS_DB_NAME"
                }
            }
          }
          env {
            name = "OCS_DB_SERVER"
            value_from {
                config_map_key_ref {
                    name = "ocsinvetory-env"
                    key = "OCS_DB_SERVER"
                }
            }
          }
          env {
            name = "OCS_DB_PORT"
            value_from {
                config_map_key_ref {
                    name = "ocsinvetory-env"
                    key = "OCS_DB_PORT"
                }
            }
          }
          env {
            name = "OCS_DB_USER"
            value_from {
                secret_key_ref {
                    name = "ocsinvetory-auth"
                    key = "username"
                }
            }
          }
          env {
            name = "OCS_DB_PASS"
            value_from {
                secret_key_ref {
                    name = "ocsinvetory-auth"
                    key = "password"
                }
            }
          }
        }
      }
    }
  }
}

deploy service 

resource "kubernetes_service" "ocsinvetory" {
  metadata {
    name = "ocsinvetory"
    namespace = "ocsinvetory"
  }
  spec {
    selector = {
      app = "ocsinvetory"
    }
    session_affinity = "ClientIP"
    port {
      name = "http-web"
      port        = 80
      target_port = 80
    }
    port {
      name = "https-web"
      port        = 443
      target_port = 443
    }

    type = "ClusterIP"
  }
}

deploy ingress 

resource "kubernetes_ingress" "ocsinvetory" {
  metadata {
    name = "ocsinvetory"
    annotations = {
      "kubernetes.io/ingress.class" = "traefik"
      #"ingress.kubernetes.io/ssl-redirect" = "true"
    }
    namespace = "ocsinvetory"
  }

  spec {
    rule {
      host = "ocs.domain"
      http {
        path {
          backend {
            service_name = "ocsinvetory"
            service_port = "http-web"
          }
          path = "/"
        }
      }
    }
    #tls {
     # hosts = ["ocs.domain"]
      #secret_name = "tls-ocsinvetory"
    #}
  }
}

I believe that OCS has coverage in its operation on the docker compose, but I would be grateful if I could help to run on kubernetes

Thansk!

gillesdubois commented 3 years ago

Hi @jmateusousa

Since you closed this issue you managed to found a solution ?

Regards, Gilles.

jmateusousa commented 3 years ago

Hi @gillesdubois,

Yes, the db was missing popular with the tables, that was the problem = /

I'm going to do a PR, with all the steps to deploy OCS on kubernetes, what do you think?

gillesdubois commented 3 years ago

Hi,

It would be nice indeed :)

Regards, Gilles.

Note : If you do a PR, please do it on the image, the stack is not used anymore