7.2. Kubernetes Quickstart#

In this lab you’ll use Kubernetes to deploy Dokuwiki. By the end of the lab you should be able to confirm that your GKE cluster is working and have templates to update for the next milestone.

Create a Dokuwiki Container#

To Kubernetes, everything is a resource. Resources can be loaded from a file (like you’re about to do) or created automatically by a program. When resources are loaded from a file the files are YAML format. YAML files can have multiple resource definitions separated by --- on a line by themselves.

To start let’s create a pod with Dokuwiki. Copy and paste that YAML into a file called deployment/pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: dokuwiki-pod
  labels:
    function: app
spec:
  containers:
  - name: dokuwiki-container
    image: bitnami/dokuwiki:latest
    ports:
    - containerPort: 8080

Apply the configuration:

$ kubectl apply -f pod.yaml

Verify that the pod has started:

$ kubectl get all 

Once started inspect the pod:

$ kubectl describe pod/dokuwiki-pod

To check the Apache logs:

$ kubectl logs pod/dokuwiki-pod

Manually Access the Container#

There’s no way to access the pod from outside our node yet. The kubectl command gives us a way to access a pod for debugging purposes.

$ kubectl port-forward dokuwiki-pod 8080:8080

Now browse to localhost:8080. You should see Dokuwiki!

Expose the Container Permanently#

In order to maintain external access to the container you need to define a service. Here’s a service definition. Copy and paste that YAML into a file called service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: dokuwiki-svc
spec:
  type: LoadBalancer
  selector:
    function: app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

Apply the configuration:

$ kubectl apply -f service.yaml

Verify that the service is present:

$ kubectl get all 

Inspect the service more closely:

$ kubectl describe service/dokuwiki-svc

The service type LoadBalancer will cause Google to allocate an IP address for your service. The process may take a few minutes. Once you see an IP address navigate there with your browser.

Delete the Resources#

Let’s clean up:

$ kubectl delete pod/dokuwiki-pod svc/dokuwiki-svc