cloudsoft.io

Discovery Example: Kubernetes Sock Shop

The Sock Shop discovery demo consists of the following items:

Deploying Sock Shop

This example deploys a version of the common microservices sockshop, e.g. using minikube. This modified version includes extra labels which are used by AMP to automatically organise the entities retrieved from the Kubernetes deployment.

To install this version of sock shop, download sockshop.zip and follow the instructions in the README.md. If minikube is already configured appropriately, the following command should work:

kubectl create -f sock-shop

Setting up AMP

We need to tell AMP how to connect to the Kubernetes where Sock Shop is running. This is done by defining a location in AMP, extending the kubernetes location type. Edit the sockshop-location.yaml file to point to your Kubernetes endpoint (supplying the other parameters commented there, if required), then install with br catalog add sockshop-location.yaml. This will add a location kubernetes-sockshop which is referenced in our deployment.

By default AMP will use the kubectl command as configured on the server where AMP is running, so for this demo, if Sock Shop was set up by running kubectl at the AMP server (e.g. both are on your machine), it is not necessary to define a location. If this is the case, you should edit the blueprint we deploy in the next step, remove the line which says location: kubernetes-sockshop.

Deploying the Example

Once the Sock Shop app has been deployed to Kubernetes and the location defined in AMP, you can deploy the example blueprint. To deploy it, run the following command:

br deploy sockshop-groups.yaml

Example Blueprint

The example blueprint starts with the following section:

services:
  - type: kubernetes-discovery
    name: Discovered Entities
    location: kubernetes-sockshop
    brooklyn.initializers:
      - type: kubernetes-labels-compliance-check
    brooklyn.config:
      namespace: sock-shop
      kubernetes.auto-organize-labels: true

This instructs AMP to connect to the Kubernetes deployment via the kubernetes-sockshop location. The kubernetes-discovery entity will then search for Kubernetes Pods, Services, etc. and create AMP entities representing those discovered.

In sockshop-discovery.yaml, the brooklyn.initializers section adds a compliance check that verifies common Kubernetes labels are set against discovered resources.

The kubernetes.auto-organize-labels config key instructs the Kubernetes Discovery entity to create an Auto-Managed Applications entity, under which the Pods, Services etc. will be automatically arranged, based on the common labels suggested in the Kubernetes documentation.

Note: The default value for this config key is true, so it is not necessary to provide it; it is included here for clarity. To disable auto-management, set the value of this key to false.

The sockshop-groups.yaml also shows how to provide your own structure for the managed application, should you not wish to use auto-arrangement, using the org.apache.brooklyn.entity.group.DynamicGroup entity to create a dynamically-updated group of entities.