This will explain how to create a Tanzu GemFire cluster or service instance with the Tanzu GemFire for Redis Apps add-on enabled. - Tanzu GemFire - Tanzu GemFire for VMs - Tanzu GemFire for Kubernetes

VMware Tanzu GemFire

Prerequisites

Start a VMware Tanzu GemFire Cluster

  1. Open a terminal window.

  2. In the terminal window, confirm that you have installed Tanzu GemFire 9.15 or later by running:

    gfsh version
    

    The output text should read 9.15.0 or later. If it does not, download and install Tanzu GemFire 9.15 or later. For installation instructions, see Installing VMware Tanzu GemFire in the VMware Tanzu GemFire documentation.

  3. Start the GemFire CLI, gfsh, by running:

    gfsh
    
  4. At the gfsh prompt, start a locator for managing the VMware Tanzu GemFire cluster:

    gfsh> start locator
    
  5. After the locator has started, start a server. Use the --classpath configuration option to specify the filepath to the folder where you unzipped the Tanzu GemFire for Redis Apps add-on files to enable the add-on:

    gfsh> start server --name=redisServer1 --locators=localhost[10334] --server-port=40404 --classpath=/path/to/gemfire-for-redis-apps/folder/lib/* --J=-Dgemfire-for-redis-enabled=true
    
  6. Start an additional server with the add-on enabled by running the same start server command with different values for the --name and --gemfire-for-redis-port parameters:

    gfsh> start server --name=redisServer2 --locators=localhost[10334] --server-port=40405 --classpath=/path/to/gemfire-for-redis-apps/folder/lib/* --J=-Dgemfire-for-redis-port=6380  --J=-Dgemfire-for-redis-enabled=true
    
  7. Your GemFire cluster should now be running with one locator and two servers, ready to connect with a Redis client. Keep the terminal with gfsh open and running to allow you to easily shut down the Tanzu GemFire cluster after you complete your tasks.

  8. Open another terminal window.

  9. To confirm that the cluster is running as expected, in a separate terminal start redis-cli in cluster mode, and identify the port of one of the Tanzu GemFire for Redis Apps servers started above. If using 6379, redis-cli will default to this port, so there’s no need to specify it when starting the Redis CLI.

    $ redis-cli -c ping
    
  10. Once connected, run the PING command using redis-cli. If the server is functioning properly, you should see a response of PONG.

Shut Down the VMware Tanzu GemFire Cluster

  1. To shut down the VMware Tanzu GemFire cluster that you started, run the command below in the terminal window with gfsh running.

    Warning: This command shuts down the entire VMware Tanzu GemFire cluster. All data in the cluster will be lost.

    gfsh> shutdown --include-locators=true
    
  2. To confirm that everything has shut down correctly, if you execute a Redis command in redis-cli you should see the following message:

    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    

VMware Tanzu GemFire for VMs

Prerequisites

Confirm that VMware Tanzu GemFire Service Instance is Available in the Marketplace

The following instructions use the CF CLI, however users can also confirm if they have the Apps Manager user interface available to them.

  1. Log in to your Tanzu Application Service cf login
  2. Once logged in, run the command to see available services in the marketplace cf marketplace

You should see an output similar to the following

Start a VMware Tanzu GemFire Service Instance with GemFire For Redis Apps add-on Enabled

  1. Open a terminal window and log in to the space you would like to start the GemFire for VMs service instance.

  2. Enable APIs for Redis and add the “redis” tag to your VMware Tanzu GemFire for VMs service.

  3. When creating a new service, include -c '{"gemfire_for_redis_enabled":true, "gemfire_for_redis_redundant_copies":N} -t redis to the cf create-service command. N can be 0,1,2 or 3 and sets the number of redundant copies created. If not set, redundant copies will default to 1.

    For example:

    $ cf create-service p-cloudcache PLAN-NAME YOUR-SERVICE-INSTANCE-NAME -c '{"gemfire_for_redis_enabled":true,"gemfire_for_redis_redundant_copies":2}' -t redis
    
  4. When updating an existing service, add -c '{"gemfire_for_redis_enabled":true, "gemfire_for_redis_redundant_copies":N} -t "redis to the cf update-service command. N can be 0,1,2 or 3 and sets the number of redundant copies created. If not set, redundant copies will default to 1.

    For example:

    $ cf update-service YOUR-SERVICE-NAME -c '{"gemfire_for_redis_enabled":true,"gemfire_for_redis_redundant_copies":2}' -t "redis"
    

    Note: Updating the service causes all members of the cluster to restart.

  5. (Optional) Transport Layer Security (TLS) VMware Tanzu GemFire for VMs allows service instances to be created with Transport Layer Security (TLS) enabled. The behavior of TLS with GemFire for VMs and GemFire for Redis Apps differs from the Redis for TAS tile, which allows TLS and non-TLS ports to be active at the same time on a single service instance. GemFire for VMs only allows TLS to be on or off, not both/optional. TLS can only be enabled during service instance creation. If you enable TLS, all connections must be made using a TLS-capable client. The non-TLS port will be unavailable.

To enable GemFire for Redis Apps and TLS on a VMware Tanzu GemFire for VMs service instance, add tls:true to the parameters passed to the cf create-service command:

For example:

$ cf create-service p-cloudcache PLAN-NAME YOUR-SERVICE-INSTANCE-NAME -c '{"gemfire_for_redis_enabled":true,"tls":true}' -t redis

Note: This enables TLS for the entire cluster.

Confirm that the add-on is enabled.

To confirm that the GemFire for Redis Apps add-on is enabled, when the cluster is up and running, confirm that the GEMFIRE_FOR_REDIS region is present in the cluster.

  1. Create a service key by running the following command: cf create-service-key MY-SERVICE-INSTANCE MY-KEY
  2. Inspect the service key: cf service-key MY-SERVICE-INSTANCE MY-KEY

    The returns a JSON response (VCAP_SERVICES) which includes a connection string to use with GemFire Shell (GFSH). For example:

    {...
     "gfsh_login_string": "connect
      --url=https://cloudcache-1.example.com/gemfire/v1
      --user=cluster_operator_XXX --password=cluster_operator-password --skip-ssl-validation"
    }
    
  3. Open a different terminal window.

  4. In the terminal window, confirm that you have installed Tanzu GemFire 9.15 or later by running:

       gfsh version
    

    The output text should read 9.15.0 or later. If it does not, download and install Tanzu GemFire 9.15 or later. For installation instructions, see Installing VMware Tanzu GemFire in the VMware Tanzu GemFire documentation.

  5. Start the GemFire CLI, gfsh, by running:

    gfsh
    
  6. Copy the content following the gfsh_login_string in the service instance key (step 2) and paste it into the GFSH terminal.
    gfsh connect --url=https://cloudcache-1.example.com/gemfire/v1 --user=cluster_operator_XXX --password=cluster_operator-password --skip-ssl-validation
    
  7. Once connected to the service instance run the list regions command

    gfsh list regions
    

    The output should include the following:

    List of regions
    -----------------
    GEMFIRE_FOR_REDIS
    

Congrats! The service instance is up and running and now able to have Redis client applications bind to the GemFire service instance.

  • For information on how to bind a Redis client application to the GemFire service instance, refer to Application Development
  • For more information about connecting to a GemFire service instance, see Accessing a Service Instance in the Tanzu GemFire for VMs documentation.

VMware Tanzu GemFire for Kubernetes

Start a VMware Tanzu GemFire Kubernetes Cluster

Follow the steps in this section to create a Tanzu GemFire for Kubernetes cluster with the Tanzu GemFire for Redis Apps add-on enabled.

Prerequisites

  • A Kubernetes Cluster with the VMware Tanzu GemFire for Kubernetes v2.0+ Operator installed.
  • A VMware Tanzu Network account or the ability to access the [Tanzu GemFire for Redis Apps]https://network.tanzu.vmware.com/products/tanzu-gemfire-for-redis-apps) image.

Start a VMware Tanzu GemFire Kubernetes Cluster

  1. Follow the instructions in the GemFire for Kubernetes documentation to install the GemFire Operator version 2.0.
  2. Once the operator is installed create a yaml file that will be used to start your GemFire cluster, note the name of the file as this will be used in the next step.

    For example, a simple yaml file may look like the following:

    apiVersion: gemfire.vmware.com/v1
    kind: GemFireCluster
    metadata:
    name: gemfirecluster-with-redis-sample
    spec:
    # Avoid using the "latest" tag in production as it is harder to track which
    # version of the image is running and may cause members to upgrade
    # unexpectedly.
    image: registry.tanzu.vmware.com/pivotal-gemfire/vmware-gemfire:9.15.1
    # Set antiAffinityPolicy to "Cluster" or "Full" in production to limit the
    # chance of data loss.
    antiAffinityPolicy: None
    security:
     tls: {}
    metrics:
     emission: Default
    locators:
     replicas: 2
     resources:
       requests:
         memory: 1Gi
    servers:
     replicas: 2
     resources:
       requests:
         memory: 1Gi
     libraries:
       - name: gemfire-for-redis-apps
         container:
           image: registry.tanzu.vmware.com/tanzu-gemfire-for-redis-apps/gemfire-for-redis-apps:1.0.1
           path: "/gemfire-for-redis-apps/*"
           imagePullSecretRef:
             name: image-pull-secret
     overrides:
       jvmOptions: ["-Dgemfire-for-redis-enabled=true"]
    
  3. Create a Gemfire cluster with GemFire for Redis Apps by applying the file created above to your Kubernetes cluster.

    kubectl apply -f GEMFIRE-CLUSTER-YAML-FILE.yaml -n NAMESPACE-NAME
    
  4. Once the cluster has started running confirm that GemFire for Redis Apps has been deployed correctly. This can be accomplished by first connecting to the GemFire cluster’s server pod, and checking the version.

  5. Start the GemFire CLI (gfsh) on a server pod by running the following command kubectl -n NAMESPACE-NAME exec -it NAME-OF-GEMFIRE-SERVER-POD-0 -- gfsh

  6. Once GFSH is up and running, run the version command gfsh> version --full
  7. The output should look similar to the following:

    ...
    ----------------------------------------
    VMware GemFire for Redis Apps
    ----------------------------------------
    GemFire-For-Redis-Apps-Source-Repository: support/1.0
    GemFire-For-Redis-Apps-Source-Revision: 496078ba99319578aa235d084f46745d89cf2d5f
    GemFire-For-Redis-Apps-Version: 1.0.1
    GemFire-For-Redis-Apps-Source-Date: 2022-07-28 10:04:01 -0700
    ...
    
    
  8. Exit the current GFSH connection gfsh> exit

  9. Now we will confirm that GemFire for Redis Apps has created the default region that will hold our Redis data.

  10. Start gfsh on a locator pod kubectl -n NAMESPACE-NAME exec -it NAME-OF-GEMFIRE-LOCATOR-POD-0 -- gfsh

  11. Connect to the locator using the connect command: gfsh> connect --locator=NAME-OF-GEMFIRE-LOCATOR-POD-0[10334]
  12. List the cluster regions
    • gfsh> list regions
  13. The output should be similar to the following:
    List of regions
    -----------------
    GEMFIRE_FOR_REDIS
    
  14. Exit the current GFSH connection gfsh> exit
  15. With the GemFire cluster and the GemFire for Redis Apps add-on running, we will now create a Service that will allow us to connect the Redis CLI to the cluster.

You can use the following example to create a yaml file for the new service:

  apiVersion: v1
  kind: Service
  metadata:
    name: gemfire-for-redis
  spec:
    clusterIP: None
    ports:
      - port: 6379
        targetPort: 6379
        protocol: TCP
        name: redis-port
    selector:
        gemfire.vmware.com/app: NAME-OF-GEMFIRE-SERVER-POD

Make sure you have the correct selector in the above yaml. You can verify this by checking the labels on any of the server pods with the following command.

kubectl describe pod NAME-OF-YOUR-CLUSTER-server-0 -n NAMESPACE-NAME
  1. Apply the above yaml to the kubernetes cluster to create the new Service.
    kubectl apply -f FILENAME-OF-SERVICE.yaml -n NAMESPACE-NAME
    

This service is not automatically created or updated when there are any changes made to the GemFire cluster. If the selector or target-port change, you will need to update this service manually.

  1. Next, deploy a pod with the Redis CLI to the Kubernetes cluster that will allow us to interact with the GemFire for Redis Apps add-on. Save the below yaml into a file called redis-cli.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: redis
    spec:
    containers:
    - name: redis-cli
      image: redis:6.2.7
      ports:
       - containerPort: 6379
    
  2. Apply the above yaml to the kubernetes cluster.

    kubectl apply -f redis-cli.yaml -n NAMESPACE-NAME
    
  3. Connect to the Redis CLI pod.

    kubectl -n NAMESPACE-NAME exec -it redis -- /bin/bash
    
  4. Start redis-cli.

    redis-cli -h gemfire-for-redis -p 6379 -c
    
  5. Run the PING command, and you should receive a response of PONG.

Shut Down the VMware Tanzu GemFire for Kubernetes Cluster

To shut down the GemFire for Kubernetes cluster, follow the steps in Create or Delete a Tanzu GemFire Cluster in the Tanzu GemFire for Kubernetes documentation.

check-circle-line exclamation-circle-line close-line
Scroll to top icon