Skip to main content
Version: 5.17

Tutorial: Configure TLS

Learn how to secure a Hazelcast cluster with TLS using Operator.

Overview​

In this tutorial, you'll do the following:

  • Create a Kubernetes Secret with a TLS certificate and key.
  • Deploy a Hazelcast cluster with TLS (mTLS) encryption enforced between members.
  • Deploy Management Center to monitor your Hazelcast cluster.
  • Connect to your cluster using TLS to encrypt member-to-client network traffic.

The tutorial should take approximately 10 minutes to complete.

Prerequisites​

Before you begin, make sure that you have:

Create a Kubernetes secret with a TLS certificate and key​

  1. Generate a TLS certificate and key in PEM format using OpenSSL.

    shell
    openssl req -x509 -sha256 -nodes -days 3650 -subj '/CN=example' -addext "subjectAltName=DNS:example" -newkey rsa:2048 -outform pem -keyout example.key -out example.crt -addext "extendedKeyUsage=serverAuth,clientAuth"
  2. Create a Kubernetes secret with the TLS certificate and key.

    shell
    kubectl create secret generic example \
    --from-file=tls.crt=example.crt \
    --from-file=tls.key=example.key
    note

    You can also provide a CA certificate to create a truststore. For more information, see TLS.

Deploy a Hazelcast cluster with TLS​

  1. Create a secret with your Hazelcast Enterprise License.

    shell
    kubectl create secret generic hazelcast-license-key --from-literal=license-key=<hz-license-key>
  2. Create the Hazelcast cluster with TLS configured.

    yaml
    kubectl apply -f - <<EOF
    apiVersion: hazelcast.com/v1alpha1
    kind: Hazelcast
    metadata:
    name: hazelcast
    spec:
    clusterSize: 3
    licenseKeySecretName: hazelcast-license-key
    tls:
    secretName: example
    exposeExternally:
    type: Smart
    discoveryServiceType: LoadBalancer
    memberAccess: LoadBalancer
    EOF
  3. Check the cluster status:

    shell
    kubectl get hazelcast hazelcast
    NAME STATUS MEMBERS
    hazelcast Running 3/3
  4. Fetch the external addresses of the cluster:

    shell
    kubectl get hazelcastendpoint --selector="app.kubernetes.io/instance=hazelcast"
    NAME TYPE ADDRESS
    hazelcast Discovery 198.51.100.18:5701
    hazelcast-0 Member 198.51.100.33:5701
    hazelcast-1 Member 198.51.100.55:5701
    hazelcast-2 Member 198.51.100.37:5701
    hazelcast-wan WAN 198.51.100.18:5710

Deploy Management Center​

Enabling TLS for a Hazelcast cluster adds an essential layer of security to protect data during communication. When TLS is enabled, all clients, including Management Center, must be configured with the appropriate TLS certificates to establish a secure connection with the Hazelcast cluster.

Apply the Management Center custom resource:

yaml
kubectl apply -f - <<EOF
apiVersion: hazelcast.com/v1alpha1
kind: ManagementCenter
metadata:
name: managementcenter
spec:
repository: 'hazelcast/management-center'
licenseKeySecretName: hazelcast-license-key
externalConnectivity:
type: LoadBalancer
hazelcastClusters:
- address: hazelcast
name: dev
tls:
secretName: example
EOF

Connect to the Hazelcast cluster over TLS​

  1. Open the examples folder to access all sample clients:

    shell
    cd hazelcast-platform-operator-tls

    The sample code for this tutorial is in the docs/modules/ROOT/examples/ directory.

  2. Configure the Hazelcast client with the TLS certificate:

    note

    CLC must be installed in your system. See the CLC installation instructions.

    Add the cluster configuration to CLC:

    shell
    clc config add hz cluster.name=dev cluster.address=<EXTERNAL-IP> ssl.enabled=true ssl.server=example ssl.ca-path=<PATH/TO/example.crt>
  3. Build and run the Hazelcast client example:

    shell
    clc -c hz map size

Clean up​

To clean up the created resources, remove all Custom Resources and secrets:

shell
kubectl delete $(kubectl get hazelcast,managementcenter -o name)
kubectl delete secret example

Summary​

In this tutorial, you learned how to:

  • Create a Kubernetes Secret with a TLS certificate and key.
  • Deploy a Hazelcast cluster with TLS (mTLS) encryption enforced between members.
  • Deploy Management Center to monitor your Hazelcast cluster.
  • Connect to your cluster using TLS to encrypt member-to-client network traffic.

Next steps​

See also: