You deploy the second application, a PHP guestbook application with MongoDB to your Supervisor by using kubectl and YAML input.

Procedure

  1. Log in to the Supervisor as a vCenter Single Sign-On Administrator user.
    kubectl vsphere login --server supervisor_cluster_IP_address --TanzuKubernetesCluster tanzu_Kubernetes_cluster_name --TanzuKubernetesClusterNamespace tanzu_kubernetes_cluster_namespace --vsphere-username supervisor_cluster_administrator
  2. Switch the kubectl context to the sfo-w01-ns01 vSphere Namespace.
    kubectl config set-context sfo-w01-ns01
  3. Create a mongo-deployment.yaml file with the following contents.
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mongo
      labels:
        app.kubernetes.io/name: mongo
        app.kubernetes.io/component: backend
    spec:
      selector:
        matchLabels:
          app.kubernetes.io/name: mongo
          app.kubernetes.io/component: backend
      replicas: 1
      template:
        metadata:
          labels:
            app.kubernetes.io/name: mongo
            app.kubernetes.io/component: backend
        spec:
          containers:
          - name: mongo
            image: mongo:4.2
            args:
              - --bind_ip
              - 0.0.0.0
            resources:
              requests:
                cpu: 100m
                memory: 100Mi
            ports:
            - containerPort: 27017
  4. Apply the MongoDB deployment.
    kubectl apply -f c:\kube\yaml\mongo-deployment.yaml
  5. Create a mongo-service.yaml file with the following contents.
    apiVersion: v1
    kind: Service
    metadata:
      name: mongo
      labels:
        app.kubernetes.io/name: mongo
        app.kubernetes.io/component: backend
    spec:
      ports:
      - port: 27017
        targetPort: 27017
      selector:
        app.kubernetes.io/name: mongo
        app.kubernetes.io/component: backend
  6. Apply the MongoDB service configuration.
    kubectl apply -f c:\kube\yaml\mongo-service.yaml
  7. Create a frontend-deployment.yaml file with the following contents.
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: frontend
      labels:
        app.kubernetes.io/name: guestbook
        app.kubernetes.io/component: frontend
    spec:
      selector:
        matchLabels:
          app.kubernetes.io/name: guestbook
          app.kubernetes.io/component: frontend
      replicas: 3
      template:
        metadata:
          labels:
            app.kubernetes.io/name: guestbook
            app.kubernetes.io/component: frontend
        spec:
          containers:
          - name: guestbook
            image: paulczar/gb-frontend:v5
            # image: gcr.io/google-samples/gb-frontend:v4
            resources:
              requests:
                cpu: 100m
                memory: 100Mi
            env:
            - name: GET_HOSTS_FROM
              value: dns
            ports:
            - containerPort: 80
  8. Apply the frontend deployment.
    kubectl apply -f c:\kube\yaml\frontend-deployment.yaml
  9. Create a frontend-service.yaml file with the following contents.
    apiVersion: v1
    kind: Service
    metadata:
      name: frontend
      labels:
        app.kubernetes.io/name: guestbook
        app.kubernetes.io/component: frontend
    spec:
      type: LoadBalancer
      ports:
      - port: 80
      selector:
        app.kubernetes.io/name: guestbook
        app.kubernetes.io/component: frontend
  10. Apply the MongoDB deployment.
    kubectl apply -f c:\kube\yaml\frontend-service.yaml
  11. Find the guestbook frontend load balancer external IP address.
    kubectl get svc frontend

    You get a return value for the frontend load balancer external IP address.

    kubectl get svc frontend
    
    NAME       TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
    frontend   LoadBalancer   100.200.2.109   192.168.21.4   80:30910/TCP   101s
  12. After the deployment completes, open a Web browser and enter the load balancer IP from the previous step.

Results

A new browser window or tab opens with the "Guestbook" heading and a text box below it. This is the web interface for your guestbook website.

If you enter text in the text box click the Submit button and the text appears below.