static-page-k8s

This is a sample code to demonstrate how to deploy a simple static page to the EnSaaS 4.0.

Deploying to the EnSaaS 4.0

1. Getting Your Own Credentials

Go to your workspace or namespace and download the config key required to manipulate your Kubernetes resources.

get-config

You will get prompted to download a config file which contains important credentials. Please make sure you secure this file and DO NOT LET ANYONE ELSE ACCESS YOUR CONFIG FILE. You may rename it to whatever you want, say wisepaas-config, and then save it to $HOME/.kube if you are using MacOS.


2. Setting Up KUBECONFIG

If you already have minikube installed on your local machine, you will have a file called config in the directory $HOME/.kube, which is the default file used by Kubernetes. After you start the minikube, you can type kubectl config view to see the information inside this config file.

You may overwrite the KUBECONFIG environment variable to direct Kubernetes to use the new one that you just downloaded, type export KUBECONFIG=$HOME/.kube/wisepaas-config. Again, you can name it accroding to personal preference. Just make sure that the envrironment variable matches your file name.


3. Clone the Sample Code from WISE-PaaS GitHub

git clone git@github.com:allguitars/static-page-k8s.git
cd static-page-k8s/

4. Building & Pushing Docker Image

  • Specify a tag when building the image.

    docker build -t <DockerHubAccount>/<ImageName>:<Tag> .

    For example: wise-paas/static-k8s:v1.0.0


  • Push the new image to your own Docker Repository.

    docker push <DockerHubAccount>/<ImageName>:<Tag>

5. Do a Little Bit Tuning

It requires some minimun effort to take this code and deploy it to the EnSaaS 4.0.

I. Setting Up the Host

Modify the host attribute in ./k8s-config/ingress-service.yaml.

ingress-host


Format:

ApplicationName.Namespace.ClusterName.internal

Note that en.internal keyword is required at the end of the string.


II. Change the Docker Image Name

Change the image attribute inside ./k8s-config/static-deployment.yaml file according to the image you just built. You may also leave this setting with the default value to use the image we have built and pushed to the EnSaaS official Docker Hub registry.

<DockerHubAccount>/<ImageName>:<Tag>

Here is the example in this code:

docker-image


III. Setting Up the Resource Usage

Modify the resources attribute inside ./k8s-config/static-deployment.yaml file. This example only uses 10m of the CPU because it is just a static webpage. However, you may try to minimize these values as possible as you can to optimiaze the resource utilization.

resources


5. Applying the Configuration

Note: Always remember to specify the namespace that you are working on while applying the Kubernetes configuration.

The following screenshot shows that the namespace is playgroud. Yours might be different.

namespace


Apply the Kubernetes configuration.

kubectl apply -f k8s-config/ --namespace <NameSpace>

Check all resources (also with namespace):

kubectl get all --namespace playground

NAME                                     READY   STATUS    RESTARTS   AGE
pod/static-deployment-5d996d5d54-97zql   1/1     Running   0          124m

NAME                                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
service/static-cluster-ip-service   ClusterIP   10.0.201.35   <none>        3000/TCP   124m

NAME                                READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/static-deployment   1/1     1            1           124m

NAME                                           DESIRED   CURRENT   READY   AGE
replicaset.apps/static-deployment-5d996d5d54   1         1         1       124m

6. Verifying the Application

In the sample code, we set the host for the Ingress service.

host: staticpage.devspace.eks004.en.internal

So, to see the page, we need to go to the following URL:

http://staticpage-devspace-eks004.sa.wise-paas.com


Mapping rule -- host vs. URL

  • host

    {AppName}.{Namespace}.{ClusterName}.en.internal
    
  • External URL

    {AppName}-{Namespace}-{Cluster}.sa.wise-paas.com
    

The page should look like:

ensaas-4.0