Google Cloud Platform with Kubernetes

This guide article will walk you through the steps for deploying PSPDFKit Server to the Google Cloud Platform with Kubernetes.

Creating a Google Cloud Project

To create a Google Cloud project, please refer to the steps outlined in the Google Cloud Platform Documentation.

Setting Up Google Cloud SDK

To be able to deploy PSPDFKit Server to the Google Cloud Platform with Kubernetes, you have to set up the gcloud utility in order to manage your Kubernetes cluster in the command line.

To install gcloud, follow the installation instructions for your platform:

kubectl is a utility for running commands against Kubernetes clusters. After installing gcloud, add the kubectl components by running the following command:

gcloud components install kubectl

Make sure to set the compute zone to the one you want to deploy to. In this example, we are using europe-west2-c, but you can also pick another one if you are not located in Europe. Then insert it into the example below:

gcloud config set compute/zone europe-west2-c

Now run gcloud compute zones list to get a list of all available compute zones.

Creating a Kubernetes Cluster

To create a Kubernetes cluster with the name pspdfkit-example-cluster, run the following:

gcloud container clusters create pspdfkit-example-cluster

This will create a cluster using the default settings. To get an overview of your clusters, visit the Container Engine dashboard.

Container Engine Dashboard

Run the following command to make sure kubectl is connected to your cluster:

kubectl get pods

This command should print No resources found. When you get an error, try to authenticate to the Google Cloud Platform with gcloud auth application-default login.

Creating a Google Cloud SQL PostgreSQL Database Instance

In order to run PSPDFKit Server, you will need to set up a Postgres database for it. To do this, go to the Google Cloud SQL Instances page and click on Create Instance.

create instance

Then you will be able to select a database engine for Google Cloud SQL to run on. Here you need to select PostgreSQL.

select database engine

Finally, you have to set an instance ID, the default user password, and the region of the database.

postgres settings

Make sure to choose PostgreSQL 11 for the database version.

Connecting the Kubernetes Engine to the Cloud SQL Instance

To enable the PSPDFKit Server deployment to connect to the Cloud SQL Instance, we will use the Cloud SQL Proxy Docker image. First you need to enable the Cloud SQL Administration API. Then you have to set up a service account with access privileges for your Cloud SQL instance.

To do this, go to the service accounts page, click on Select, select your Google Cloud project, and then click on Create Service Account. Set a service account name and an ID, and make sure to select Cloud SQL Admin as the Project role and Furnish a new private key with the key type JSON.

Click on Save to save this service account and to download the service account private key file. Be sure to save this file, because you will need it later.

create service account

Run the following command to create a user named proxyuser for the Google Cloud SQL database. This user will be used to access the database from the PSPDFKit Server deployment:

gcloud sql users create proxyuser host --instance=[INSTANCE_NAME] --password=[PASSWORD]

Make sure to replace [INSTANCE_NAME] with the name of your Google Cloud SQL instance and [PASSWORD] with a password for the user.

You also need to create two secrets for the Kubernetes Engine application to be able to access the Cloud SQL instance.

To create the secret for the service account, replace [PROXY_KEY_FILE_PATH] in the following command with the path where you saved the service accounts’ private key, and then run it:

kubectl create secret generic cloudsql-instance-credentials \

The second secret you need to create provides the proxy user account and its password. Here you need to replace [PASSWORD] with the password you set for the proxy user you just created:

kubectl create secret generic cloudsql-db-credentials \
    --from-literal=username=proxyuser --from-literal=password=[PASSWORD]

Creating a ConfigMap

ConfigMaps allow you to decouple configuration artifacts from image content. To create the pspdfkit-config ConfigMap, run the following command:

kubectl create configmap pspdfkit-config

After the ConfigMap is created, you can edit it with the following:

kubectl edit configmap pspdfkit-config

This should open the created ConfigMap in your editor. Edit the file to match the following file and replace activation_key with your activation key:

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving,
# this file will be reopened with the relevant failures.
apiVersion: v1
  api_auth_token: secret
  dashboard_password: secret
  dashboard_username: dashboard
  jwt_algorithm: RS256
  jwt_public_key: |
    -----BEGIN PUBLIC KEY-----
    -----END PUBLIC KEY-----
  pgdatabase: pspdfkit
  secret_key_base: secret-key-base
kind: ConfigMap

Don’t change anything that comes after the kind: ConfigMap line, because that part is autogenerated.

Creating the Services and Deployments

For the configuration of the proxy container you will use to connect to the Cloud SQL database, you will need the instance connection name of the instance. To get this, run the following command:

gcloud sql instances describe [INSTANCE_NAME]

The output of this command will contain a line like this, where pspdfkit-example-project:europe-west1:pspdfkitexampledb is the name of the instance:

connectionName: pspdfkit-example-project:europe-west1:pspdfkitexampledb

Kubernetes services and deployments can be configured in a file. To run PSPDFKit Server, you have to define a service and a deployment for the PSPDFKit Server. To do this, create the pspdfkit.yml file in the current directory, replace the version in the image pspdfkit/pspdfkit:2019.4.1 with the latest PSPDFKit Server version, and replace pspdfkit-example-project:europe-west1:pspdfkitexampledb with the name of the Cloud SQL database instance from the previous command:

apiVersion: v1
kind: Service
  name: pspdfkit
    - protocol: TCP
      port: 5000
      targetPort: 5000
    app: pspdfkit
  type: LoadBalancer
apiVersion: apps/v1
kind: Deployment
  name: pspdfkit
        app: pspdfkit
        - name: cloudsql-proxy
          command: ["/cloud_sql_proxy",
            - name: cloudsql-instance-credentials
              mountPath: /secrets/cloudsql
              readOnly: true
        - image: pspdfkit/pspdfkit:2019.4.1
          name: pspdfkit
            - name: PGUSER
                      name: cloudsql-db-credentials
                      key: username
            - name: PGPASSWORD
                      name: cloudsql-db-credentials
                      key: password
            - name: PGDATABASE
                  name: pspdfkit-config
                  key: pgdatabase
            - name: PGHOST
              value: ""
            - name: PGPORT
              value: "5432"
            - name: ACTIVATION_KEY
                  name: pspdfkit-config
                  key: activation_key
            - name: API_AUTH_TOKEN
                  name: pspdfkit-config
                  key: api_auth_token
            - name: SECRET_KEY_BASE
                  name: pspdfkit-config
                  key: secret_key_base
            - name: JWT_ALGORITHM
                  name: pspdfkit-config
                  key: jwt_algorithm
            - name: JWT_PUBLIC_KEY
                  name: pspdfkit-config
                  key: jwt_public_key
            - name: DASHBOARD_USERNAME
                  name: pspdfkit-config
                  key: dashboard_username
            - name: DASHBOARD_PASSWORD
                  name: pspdfkit-config
                  key: dashboard_password
            - containerPort: 5000
              name: pspdfkit
        - name: cloudsql-instance-credentials
            secretName: cloudsql-instance-credentials

To create the services and deployments needed to run PSPDFKit Server, execute the following:

kubectl create -f ./pspdfkit.yml

Viewing the Dashboard

To be able to access the server, you have to get the external IP address that was assigned to the server. Run the following command to view all the services in your cluster, along with their assigned external IP addresses:

kubectl get services

This will show something like the following:

NAME         TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
kubernetes   ClusterIP     <none>           443/TCP          54m
pspdfkit     LoadBalancer   12.345.678.910   5000:32393/TCP   1m

Copy the EXTERNAL-IP address from the pspdfkit column and access the dashboard with the port 5000 and the /dashboard path in your web browser. In this example, you would access the dashboard with http://12.345.678.910:5000/dashboard.


Be aware that this is just an example setup, and we recommend looking deeper into the Google Cloud Platform for a production-ready setup.