Skip to content

Commit

Permalink
Update ZooKeeper Content
Browse files Browse the repository at this point in the history
Signed-off-by: mohin7 <[email protected]>
  • Loading branch information
mohin7 committed Jul 4, 2024
1 parent 79f778b commit 6c832bc
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Kubernetes has revolutionized the landscape of containerized applications, simpl

Kubernetes streamlines and automates critical tasks such as load balancing, real-time demand-based scaling, and guaranteeing application resilience through self-healing mechanisms. Through a user-friendly, declarative configuration approach, users specify their desired application configuration, and Kubernetes handles the execution. This frees developers to focus on developing exceptional applications while Kubernetes ensures they run smoothly and efficiently. In essence, Kubernetes equips users to effortlessly navigate the challenges of modern application deployment.

The Kubernetes ZooKeeper Operator, extends the Kubernetes API through a custom resource definition (CRD) tailored for ZooKeeper. By leveraging the Operator, you can effortlessly deploy, manage, and scale ZooKeeper instances within your Kubernetes ecosystem. This guide dives into the advantages, functionalities, and steps involved in deploying ZooKeeper using the Kubernetes ZooKeeper Operator. By adopting this approach, you can achieve a dynamic and efficient strategy for deploying and managing ZooKeeper on Kubernetes.
The **Kubernetes ZooKeeper Operator**, extends the Kubernetes API through a custom resource definition (CRD) tailored for ZooKeeper. By leveraging the Operator, you can effortlessly deploy, manage, and scale ZooKeeper instances within your Kubernetes ecosystem. This guide dives into the advantages, functionalities, and steps involved in deploying ZooKeeper using the Kubernetes ZooKeeper Operator. By adopting this approach, you can achieve a dynamic and efficient strategy for deploying and managing ZooKeeper on Kubernetes.

## Advantage of ZooKeeper in Kubernetes

Expand All @@ -24,18 +24,19 @@ As a distributed service, it thrives in Kubernetes environments. Inherent scalab
Integrating ZooKeeper with Kubernetes offers several benefits. The Kubernetes ZooKeeper Operator streamlines deployment and configuration. This means you can ignore manual processes and manage ZooKeeper instances centrally within Kubernetes. Kubernetes inherently scales applications based on demand, and this seamlessly extends to ZooKeeper, ensuring it can handle growing workloads. Additionally, leveraging Kubernetes self-healing capabilities makes ZooKeeper deployments more resilient. In the event of an instance failure, Kubernetes automatically restarts the ZooKeeper pod, minimizing disruption to your distributed systems. The integration also aligns perfectly with DevOps principles by facilitating smoother development and testing workflows. Deploying and managing ZooKeeper alongside your containerized applications becomes a unified process within the Kubernetes ecosystem. By combining Kubernetes ZooKeeper together, you gain a powerful and dynamic solution for managing distributed systems within modern containerized environments.

## Deploy ZooKeeper on Kubernetes

### Pre-requisites
Before deploying ZooKeeper on Kubernetes, ensure you have a functional Kubernetes cluster and a basic understanding of ZooKeeper. Here, we'll assume you've already set up your cluster. Here we are using [Kind](https://kubernetes.io/docs/tasks/tools/#kind) to set up our Kubernetes cluster. Additionally, you'll need [Helm](https://helm.sh/docs/intro/install/) installed on your Kubernetes cluster.

In this tutorial, We will use the Kubernetes ZooKeeper operator KubeDB to deploy ZooKeeper on Kubernetes. First, we need to install KubeDB on our Kubernetes cluster, which requires a license. You can obtain a free license from the [Appscode License Server](https://appscode.com/issue-license/). To get a license, use your Kubernetes cluster ID. Run the following command to retrieve your cluster ID.
Before deploying ZooKeeper on Kubernetes using, ensure you have a functional Kubernetes cluster and a basic understanding of ZooKeeper. Here, we'll assume you've already set up your cluster. Here we are using [Kind](https://kubernetes.io/docs/tasks/tools/#kind) to set up our Kubernetes cluster. Additionally, you'll need [Helm](https://helm.sh/docs/intro/install/) installed on your Kubernetes cluster.

In this tutorial, We will use the [Kubernetes ZooKeeper operator](https://kubedb.com/kubernetes/databases/run-and-manage-zookeeper-on-kubernetes/) KubeDB to deploy ZooKeeper on Kubernetes. First, we need to install [KubeDB](https://kubedb.com/) on our Kubernetes cluster, which requires a license. You can obtain a free license from the [Appscode License Server](https://appscode.com/issue-license/). To get a license, use your Kubernetes cluster ID. Run the following command to retrieve your cluster ID.


```bash
$ kubectl get ns kube-system -o jsonpath='{.metadata.uid}'
de1c6058-fa66-4d22-a7ae-d17e221c1533
```

The license server will email us with a "license.txt" file attached after we provide the necessary data. Run the following commands listed below to install KubeDB.
The license server will email us with a "license.txt" file attached after we provide the necessary data. Run the following commands listed below to install KubeDB.

```bash
$ helm install kubedb oci://ghcr.io/appscode-charts/kubedb \
Expand All @@ -58,19 +59,21 @@ kubedb kubedb-kubedb-webhook-server-7787b4c494-6qktv 1/1 Running 0
kubedb kubedb-petset-operator-54877fd499-kngl8 1/1 Running 0 5m12s
kubedb kubedb-petset-webhook-server-54c9ccbf89-t8mt8 2/2 Running 0 5m12s
kubedb kubedb-sidekick-5d9947bd9-q2gkx 1/1 Running 0 5m12s
```
```

We can go on to the next stage if every pod status is running.

## Create a Namespace

Now we'll create a new namespace in which we will deploy ZooKeeper. To create a namespace, we can use the following command:

```bash
$ kubectl create namespace demo
namespace/demo created
```

```

## Deploy ZooKeeper using Kubernetes ZooKeeper operator

We need to create a yaml manifest to deploy ZooKeeper on Kubernetes. And we will apply this yaml below,

```yaml
Expand All @@ -87,23 +90,21 @@ spec:
resources:
requests:
storage: "1Gi"
storageClassName: "gp2"
storageClassName: "standard"
accessModes:
- ReadWriteOnce
deletionPolicy: "WipeOut"
```
Let's save this yaml configuration into `zookeeper.yaml`
You can see the detailed yaml specifications in the [Kubernetes RabbitMQ documentation](https://kubedb.com/docs/latest/guides/zookeeper/).
Let's save this yaml configuration into `zookeeper.yaml`
Then create the above ZooKeeper CRO,

```bash
$ kubectl apply -f zookeeper.yaml
$ kubectl apply -f zookeeper.yaml
zookeeper.kubedb.com/zookeeper created
```
In this yaml,
* `spec.version` field specifies the version of ZooKeeper Here, we are using ZooKeeper `version 3.9.1`. You can list the KubeDB supported versions of ZooKeeper by running `$ kubectl get zookeeperversions` command.
* `spec.storage` specifies PVC spec that will be dynamically allocated to store data for this database. This storage spec will be passed to the StatefulSet created by KubeDB operator to run database pods. You can specify any StorageClass available in your cluster with appropriate resource requests.
* And the `spec.deletionPolicy` field is *Wipeout* means that the database will be deleted without restrictions. It can also be "Halt", "Delete" and "DoNotTerminate".

Once these are handled correctly and the ZooKeeper object is deployed, you will see that the following objects are created:

Expand All @@ -122,6 +123,7 @@ service/zookeeper-pods ClusterIP None <none> 2181/T
NAME TYPE VERSION AGE
appbinding.appcatalog.appscode.com/zookeeper kubedb.com/zookeeper 3.9.1 3m36s
```

We have successfully deployed ZooKeeper to Kubernetes using the Kubernetes ZooKeeper operator. Now, we will exec into the ZooKeeper pod to create some sample node and verify whether our ZooKeeper is usable or not. Before connect to the ZooKeeper pod let’s check if the ZooKeeper is ready to use,

```bash
Expand Down Expand Up @@ -157,20 +159,18 @@ kubedb

> We’ve successfully deployed ZooKeeper to Kubernetes using the Kubernetes ZooKeeper operator KubeDB. Also, we successfully accessed ZooKeeper and created a sample ZooKeeper node.


## ZooKeeper on Kubernetes: Best Practices

To guarantee the smooth operation of your ZooKeeper applications within Kubernetes, consider implementing these best practices:

* **Configuration Management:** Leverage Kubernetes ConfigMaps to store ZooKeeper configuration files for easier management and updates. Utilize Secrets for secure handling of sensitive information like ZooKeeper server credentials. Implement dynamic configuration reloading to apply changes without downtime, maintaining continuous availability.
- **Configuration Management:** Leverage Kubernetes ConfigMaps to store ZooKeeper configuration files for easier management and updates. Utilize Secrets for secure handling of sensitive information like ZooKeeper server credentials. Implement dynamic configuration reloading to apply changes without downtime, maintaining continuous availability.

* **Resource Management:** Unlike applications with varying resource demands, ZooKeeper tends to have a more predictable resource footprint. Analyze your ZooKeeper workload to determine appropriate CPU and memory requests and limits for its pods. This ensures ZooKeeper receives sufficient resources without overprovisioning that could waste cluster resources.
- **Resource Management:** Unlike applications with varying resource demands, ZooKeeper tends to have a more predictable resource footprint. Analyze your ZooKeeper workload to determine appropriate CPU and memory requests and limits for its pods. This ensures ZooKeeper receives sufficient resources without overprovisioning that could waste cluster resources.

* **Networking & Security:** Use Kubernetes Services to expose ZooKeeper to other pods in the environment. Use ClusterIP services for internal communication within the cluster. For external access, utilize NodePort or LoadBalancer services with appropriate security controls. Implement Network Policies to restrict traffic flow and ensure only authorized pods can communicate with ZooKeeper, enhancing security. Leverage Role-Based Access Control (RBAC) to restrict access to ZooKeeper resources and Pod Security Policies to enforce security standards like running containers as non-root users and preventing privileged escalation. Secure communication between ZooKeeper instances and other components by enabling TLS encryption. This protects data in transit within the cluster.
- **Networking & Security:** Use Kubernetes Services to expose ZooKeeper to other pods in the environment. Use ClusterIP services for internal communication within the cluster. For external access, utilize NodePort or LoadBalancer services with appropriate security controls. Implement Network Policies to restrict traffic flow and ensure only authorized pods can communicate with ZooKeeper, enhancing security. Leverage Role-Based Access Control (RBAC) to restrict access to ZooKeeper resources and Pod Security Policies to enforce security standards like running containers as non-root users and preventing privileged escalation. Secure communication between ZooKeeper instances and other components by enabling TLS encryption. This protects data in transit within the cluster.

* **Utilizing the Kubernetes ZooKeeper Operator:** Consider using the Kubernetes ZooKeeper Operator for simplified deployment and management. The operator automates administrative tasks and simplifies configuration and scaling. This allows for easier deployment and management of ZooKeeper instances, optimizing performance and reducing manual workload for administrators.
- **Utilizing the Kubernetes ZooKeeper Operator:** Consider using the Kubernetes ZooKeeper Operator for simplified deployment and management. The operator automates administrative tasks and simplifies configuration and scaling. This allows for easier deployment and management of ZooKeeper instances, optimizing performance and reducing manual workload for administrators.

## Conclusion

In conclusion, ZooKeeper has emerged as a powerful tool for coordinating and managing distributed applications within Kubernetes environments. Its core functionalities, including distributed locking, leader election, service discovery, and configuration management, provide a robust foundation for building resilient and scalable distributed systems. This guide has equipped you with the knowledge to deploy ZooKeeper on Kubernetes, leveraging the benefits of the Kubernetes ZooKeeper Operator for simplified management. For a deeper dive into implementing ZooKeeper with Kubernetes, the official [ZooKeeper documentation](https://zookeeper.apache.org/documentation.html) offers comprehensive resources. Remember, achieving optimal performance and reliability within your distributed system requires ongoing optimization and a strong understanding of ZooKeeper best practices. Additionally, expertise from managed Kubernetes service providers like KubeDB can be valuable in ensuring your ZooKeeper deployment maintains high availability and performance.


0 comments on commit 6c832bc

Please sign in to comment.