Cookies disclaimer

I agree Our site saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing our website without changing the browser settings you grant us permission to store that information on your device.

Create a cluster Postgres on Kubernetes





Don't forget if you need help putting your application in production, or you want it to do for you ? Open un ticket !

We will create an application Odoo with a database of Postgres and persistent storage.

Each application will have its own deployment in order to be able to resize the "Front".

1) creation of the environment:

 

We will call odoo-postgres, and I would use the template "small" for the demonstration

2) creation of storage facilities:

we are going to create 1 storage for postgres (10GB) . We will take careful note of the uuid of the service to be able to map our storage with our application.

3) creation of our deploying Postgres in our namespace:

 

{
	"name": "postgres",
	"spec": {
		"template": {
			"spec": {
				"containers": [{
					"name": "postgres",
					"image": "sameersbn/postgresql:9.5-2",
					"volumeMounts": [{
						"mountPath": "/var/lib/postgresql",
						"name": "postgres-persistent-storage"
					}],
					"env": [{
						"name": "DB_USER",
						"value": "odoo"
					}, {
						"name": "DB_PASS",
						"value": "odoo"
					}],
					"ports": [{
						"containerPort": 5432,
						"name": "db"
					}],
					"resources": {
						"limits": {
							"memory": "1Gi",
							"cpu": "1"
						}
					}
				}],
				"volumes": [{
					"image": "UUID_DU_STOCKAGE",
					"name": "postgres-persistent-storage"
				}]
			}
		},
		"replicas": 1
	}
}

 

4) Create a loadBalancer for postgres :

We create a load balancer to expose postgres in our application, Odoo, to do this you go to Menu >> Container Cloud >> Loadbalancer.

It selects the name of our deployment ( for me postgres ), the Cname is not necessary because we do not want to expose postgres on the internet, as the name we put "postgres" and the port to 5432 ( the standard port for postgresql ), the public field is not checked.

5) creation of our deployment in Odoo:

{
      "name": "odoo", 
      "spec": {
            "template": {
                  "spec": {
                        "containers": [
                              {
                                    "name": "odoo", 
                                    "image": "odoo", 
                                    "volumeMounts": [], 
                                    "env": [
                                          {
                                                "name": "PGHOST", 
                                                "value": "postgres"
                                          },
                                          {
                                                "name": "PGPORT", 
                                                "value": "5432"
                                          },
                                          {
                                                "name": "PGPASSWORD", 
                                                "value": "odoo"
                                          },
                                          {
                                                "name": "PGUSER", 
                                                "value": "odoo"
                                          }
                                    ], 
                                    "imagePullPolicy": "Always", 
                                    "ports": [
                                          {
                                                "containerPort": 8069, 
                                                "name": "odoo"
                                          }
                                    ], 
                                    "resources": {
                                          "limits": {
                                                "cpu": "1", 
                                                "memory": "1Gi"
                                          }
                                    }
                              }
                        ], 
                        "volumes": []
                  }
            }, 
            "replicas": 1
      }
}

 

6) Now we will expose our application to Odoo so that it is accessible from the browser.

To do this, we are going in the Menu >> Container Cloud >> Loadbalancer and we fill in as follows ( please note that only the cnames .apps.hebus.io are available, if you wish to put your domain you will need to create a Cname at your registrar pointing to lb.hebus.io )