Merge pull request #9196 from lucperkins/lperkins/issue-8639-cassandra-pods
Small fixes for Cassandra doc
This commit is contained in:
@@ -7,44 +7,45 @@ weight: 30
|
|||||||
---
|
---
|
||||||
|
|
||||||
{{% capture overview %}}
|
{{% capture overview %}}
|
||||||
This tutorial shows you how to develop a native cloud [Cassandra](http://cassandra.apache.org/) deployment on Kubernetes. In this instance, a custom Cassandra `SeedProvider` enables Cassandra to discover new Cassandra nodes as they join the cluster.
|
This tutorial shows you how to develop a native cloud [Cassandra](http://cassandra.apache.org/) deployment on Kubernetes. In this example, a custom Cassandra `SeedProvider` enables Cassandra to discover new Cassandra nodes as they join the cluster.
|
||||||
|
|
||||||
Deploying stateful distributed applications, like Cassandra, within a clustered environment can be challenging. StatefulSets greatly simplify this process. Please read about [StatefulSets](/docs/concepts/workloads/controllers/statefulset/) for more information about the features used in this tutorial.
|
`StatefulSet`s make it easier to deploy stateful applications within a clustered environment. For more information on the features used in this tutorial, see the [`StatefulSet`](/docs/concepts/workloads/controllers/statefulset/) documentation.
|
||||||
|
|
||||||
**Cassandra Docker**
|
**Cassandra on Docker**
|
||||||
|
|
||||||
The Pods use the [`gcr.io/google-samples/cassandra:v13`](https://github.com/kubernetes/examples/blob/master/cassandra/image/Dockerfile)
|
The `Pod`s in this tutorial use the [`gcr.io/google-samples/cassandra:v13`](https://github.com/kubernetes/examples/blob/master/cassandra/image/Dockerfile)
|
||||||
image from Google's [container registry](https://cloud.google.com/container-registry/docs/).
|
image from Google's [container registry](https://cloud.google.com/container-registry/docs/).
|
||||||
The docker image above is based on [debian-base](https://github.com/kubernetes/kubernetes/tree/master/build/debian-base)
|
The Docker image above is based on [debian-base](https://github.com/kubernetes/kubernetes/tree/master/build/debian-base)
|
||||||
and includes OpenJDK 8.
|
and includes OpenJDK 8.
|
||||||
|
|
||||||
This image includes a standard Cassandra installation from the Apache Debian repo.
|
This image includes a standard Cassandra installation from the Apache Debian repo.
|
||||||
By using environment variables you can change values that are inserted into `cassandra.yaml`.
|
By using environment variables you can change values that are inserted into `cassandra.yaml`.
|
||||||
|
|
||||||
| ENV VAR | DEFAULT VALUE |
|
| ENV VAR | DEFAULT VALUE |
|
||||||
| ------------- |:-------------: |
|
| ------------- |:-------------: |
|
||||||
| CASSANDRA_CLUSTER_NAME | 'Test Cluster' |
|
| `CASSANDRA_CLUSTER_NAME` | `'Test Cluster'` |
|
||||||
| CASSANDRA_NUM_TOKENS | 32 |
|
| `CASSANDRA_NUM_TOKENS` | `32` |
|
||||||
| CASSANDRA_RPC_ADDRESS | 0.0.0.0 |
|
| `CASSANDRA_RPC_ADDRESS` | `0.0.0.0` |
|
||||||
|
|
||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
{{% capture objectives %}}
|
{{% capture objectives %}}
|
||||||
* Create and Validate a Cassandra headless [Services](/docs/concepts/services-networking/service/).
|
* Create and validate a Cassandra headless [`Service`](/docs/concepts/services-networking/service/).
|
||||||
* Use a [StatefulSet](/docs/concepts/workloads/controllers/statefulset/) to create a Cassandra ring.
|
* Use a [`StatefulSet`](/docs/concepts/workloads/controllers/statefulset/) to create a Cassandra ring.
|
||||||
* Validate the [StatefulSet](/docs/concepts/workloads/controllers/statefulset/).
|
* Validate the [`StatefulSet`](/docs/concepts/workloads/controllers/statefulset/).
|
||||||
* Modify the [StatefulSet](/docs/concepts/workloads/controllers/statefulset/).
|
* Modify the [`StatefulSet`](/docs/concepts/workloads/controllers/statefulset/).
|
||||||
* Delete the [StatefulSet](/docs/concepts/workloads/controllers/statefulset/) and its [Pods](/docs/concepts/workloads/pods/pod/).
|
* Delete the [`StatefulSet`](/docs/concepts/workloads/controllers/statefulset/) and its [`Pod`s](/docs/concepts/workloads/pods/pod/).
|
||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
{{% capture prerequisites %}}
|
{{% capture prerequisites %}}
|
||||||
To complete this tutorial, you should already have a basic familiarity with [Pods](/docs/concepts/workloads/pods/pod/), [Services](/docs/concepts/services-networking/service/), and [StatefulSets](/docs/concepts/workloads/controllers/statefulset/). In addition, you should:
|
To complete this tutorial, you should already have a basic familiarity with [`Pod`s](/docs/concepts/workloads/pods/pod/), [`Service`s](/docs/concepts/services-networking/service/), and [`StatefulSet`s](/docs/concepts/workloads/controllers/statefulset/). In addition, you should:
|
||||||
|
|
||||||
* [Install and Configure](/docs/tasks/tools/install-kubectl/) the `kubectl` command line
|
* [Install and Configure](/docs/tasks/tools/install-kubectl/) the `kubectl` command-line tool
|
||||||
|
|
||||||
* Download [cassandra-service.yaml](/examples/application/cassandra/cassandra-service.yaml)
|
* Download [`cassandra-service.yaml`](/examples/application/cassandra/cassandra-service.yaml)
|
||||||
and [cassandra-statefulset.yaml](/examples/application/cassandra/cassandra-statefulset.yaml)
|
and [`cassandra-statefulset.yaml`](/examples/application/cassandra/cassandra-statefulset.yaml)
|
||||||
|
|
||||||
* Have a supported Kubernetes Cluster running
|
* Have a supported Kubernetes cluster running
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
**Note:** Please read the [getting started guides](/docs/setup/pick-right-solution/) if you do not already have a cluster.
|
**Note:** Please read the [getting started guides](/docs/setup/pick-right-solution/) if you do not already have a cluster.
|
||||||
@@ -53,25 +54,26 @@ To complete this tutorial, you should already have a basic familiarity with [Pod
|
|||||||
### Additional Minikube Setup Instructions
|
### Additional Minikube Setup Instructions
|
||||||
|
|
||||||
{{< caution >}}
|
{{< caution >}}
|
||||||
**Caution:** [Minikube](/docs/getting-started-guides/minikube/) defaults to 1024MB of memory and 1 CPU which results in an insufficient resource errors during this tutorial.
|
**Caution:** [Minikube](/docs/getting-started-guides/minikube/) defaults to 1024MB of memory and 1 CPU. Running Minikube with the default resource configuration may result in insufficient resource errors during this tutorial. To avoid these errors, we recommend running Minikube with 5 GB of memory and 4 CPUs:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
minikube start --memory 5120 --cpus=4
|
||||||
|
```
|
||||||
{{< /caution >}}
|
{{< /caution >}}
|
||||||
|
|
||||||
To avoid these errors, run minikube with:
|
|
||||||
|
|
||||||
minikube start --memory 5120 --cpus=4
|
|
||||||
|
|
||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
{{% capture lessoncontent %}}
|
{{% capture lessoncontent %}}
|
||||||
## Creating a Cassandra Headless Service
|
## Creating a Cassandra Headless Service
|
||||||
A Kubernetes [Service](/docs/concepts/services-networking/service/) describes a set of [Pods](/docs/concepts/workloads/pods/pod/) that perform the same task.
|
|
||||||
|
|
||||||
The following `Service` is used for DNS lookups between Cassandra Pods and clients within the Kubernetes Cluster.
|
A Kubernetes [`Service`](/docs/concepts/services-networking/service/) describes a set of [`Pod`s](/docs/concepts/workloads/pods/pod/) that perform the same task.
|
||||||
|
|
||||||
|
The following `Service` is used for DNS lookups between Cassandra `Pod`s and clients within the Kubernetes cluster.
|
||||||
|
|
||||||
{{< codenew file="application/cassandra/cassandra-service.yaml" >}}
|
{{< codenew file="application/cassandra/cassandra-service.yaml" >}}
|
||||||
|
|
||||||
1. Launch a terminal window in the directory you downloaded the manifest files.
|
1. Launch a terminal window in the directory you downloaded the manifest files.
|
||||||
1. Create a `Service` to track all Cassandra StatefulSet Nodes from the `cassandra-service.yaml` file:
|
1. Create a `Service` to track all Cassandra `StatefulSet` nodes from the `cassandra-service.yaml` file:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl create -f https://k8s.io/examples/application/cassandra/cassandra-service.yaml
|
kubectl create -f https://k8s.io/examples/application/cassandra/cassandra-service.yaml
|
||||||
@@ -81,27 +83,31 @@ The following `Service` is used for DNS lookups between Cassandra Pods and clien
|
|||||||
|
|
||||||
Get the Cassandra `Service`.
|
Get the Cassandra `Service`.
|
||||||
|
|
||||||
kubectl get svc cassandra
|
```shell
|
||||||
|
kubectl get svc cassandra
|
||||||
|
```
|
||||||
|
|
||||||
The response should be
|
The response is
|
||||||
|
|
||||||
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
```
|
||||||
cassandra None <none> 9042/TCP 45s
|
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
|
cassandra None <none> 9042/TCP 45s
|
||||||
|
```
|
||||||
|
|
||||||
If anything else returns, the service was not successfully created. Read [Debug Services](/docs/tasks/debug-application-cluster/debug-service/) for common issues.
|
Service creation failed if anything else is returned. Read [Debug Services](/docs/tasks/debug-application-cluster/debug-service/) for common issues.
|
||||||
|
|
||||||
## Using a StatefulSet to Create a Cassandra Ring
|
## Using a StatefulSet to Create a Cassandra Ring
|
||||||
|
|
||||||
The StatefulSet manifest, included below, creates a Cassandra ring that consists of three Pods.
|
The `StatefulSet` manifest, included below, creates a Cassandra ring that consists of three `Pod`s.
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
**Note:** This example uses the default provisioner for Minikube. Please update the following StatefulSet for the cloud you are working with.
|
**Note:** This example uses the default provisioner for Minikube. Please update the following `StatefulSet` for the cloud you are working with.
|
||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
{{< codenew file="application/cassandra/cassandra-statefulset.yaml" >}}
|
{{< codenew file="application/cassandra/cassandra-statefulset.yaml" >}}
|
||||||
|
|
||||||
1. Update the StatefulSet if necessary.
|
1. Update the `StatefulSet` if necessary.
|
||||||
1. Create the Cassandra StatefulSet from the `cassandra-statefulset.yaml` file:
|
1. Create the Cassandra `StatefulSet` from the `cassandra-statefulset.yaml` file:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl create -f https://k8s.io/examples/application/cassandra/cassandra-statefulset.yaml
|
kubectl create -f https://k8s.io/examples/application/cassandra/cassandra-statefulset.yaml
|
||||||
@@ -109,38 +115,36 @@ The StatefulSet manifest, included below, creates a Cassandra ring that consists
|
|||||||
|
|
||||||
## Validating The Cassandra StatefulSet
|
## Validating The Cassandra StatefulSet
|
||||||
|
|
||||||
1. Get the Cassandra StatefulSet:
|
1. Get the Cassandra `StatefulSet`:
|
||||||
|
|
||||||
```
|
```shell
|
||||||
kubectl get statefulset cassandra
|
kubectl get statefulset cassandra
|
||||||
```
|
```
|
||||||
|
|
||||||
The response should be
|
The response should be:
|
||||||
|
|
||||||
```
|
```
|
||||||
NAME DESIRED CURRENT AGE
|
NAME DESIRED CURRENT AGE
|
||||||
cassandra 3 0 13s
|
cassandra 3 0 13s
|
||||||
```
|
```
|
||||||
|
|
||||||
The StatefulSet resource deploys Pods sequentially.
|
The `StatefulSet` resource deploys `Pod`s sequentially.
|
||||||
|
|
||||||
1. Get the Pods to see the ordered creation status:
|
1. Get the `Pod`s to see the ordered creation status:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get pods -l="app=cassandra"
|
kubectl get pods -l="app=cassandra"
|
||||||
```
|
```
|
||||||
|
|
||||||
The response should be
|
The response should be:
|
||||||
|
|
||||||
```
|
```shell
|
||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
cassandra-0 1/1 Running 0 1m
|
cassandra-0 1/1 Running 0 1m
|
||||||
cassandra-1 0/1 ContainerCreating 0 8s
|
cassandra-1 0/1 ContainerCreating 0 8s
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** It can take up to ten minutes for all three Pods to deploy.
|
Please note that it may take several minutes for all three `Pod`s to deploy. Once they are deployed, the same command returns:
|
||||||
|
|
||||||
Once all Pods are deployed, the same command returns:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
@@ -149,13 +153,13 @@ The StatefulSet manifest, included below, creates a Cassandra ring that consists
|
|||||||
cassandra-2 1/1 Running 0 8m
|
cassandra-2 1/1 Running 0 8m
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Run the Cassandra utility nodetool to display the status of the ring.
|
3. Run the Cassandra [nodetool](https://wiki.apache.org/cassandra/NodeTool) to display the status of the ring.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl exec cassandra-0 -- nodetool status
|
kubectl exec -it cassandra-0 -- nodetool status
|
||||||
```
|
```
|
||||||
|
|
||||||
The response is:
|
The response should look something like this:
|
||||||
|
|
||||||
```
|
```
|
||||||
Datacenter: DC1-K8Demo
|
Datacenter: DC1-K8Demo
|
||||||
@@ -170,19 +174,17 @@ The StatefulSet manifest, included below, creates a Cassandra ring that consists
|
|||||||
|
|
||||||
## Modifying the Cassandra StatefulSet
|
## Modifying the Cassandra StatefulSet
|
||||||
|
|
||||||
Use `kubectl edit` to modify the size of a Cassandra StatefulSet.
|
Use `kubectl edit` to modify the size of a Cassandra `StatefulSet`.
|
||||||
|
|
||||||
1. Run the following command:
|
1. Run the following command:
|
||||||
|
|
||||||
```
|
```shell
|
||||||
kubectl edit statefulset cassandra
|
kubectl edit statefulset cassandra
|
||||||
```
|
```
|
||||||
|
|
||||||
This command opens an editor in your terminal. The line you need to change is the `replicas` field.
|
This command opens an editor in your terminal. The line you need to change is the `replicas` field. The following sample is an excerpt of the `StatefulSet` file:
|
||||||
|
|
||||||
**Note:** The following sample is an excerpt of the StatefulSet file.
|
```yaml
|
||||||
|
|
||||||
```
|
|
||||||
# Please edit the object below. Lines beginning with a '#' will be ignored,
|
# Please edit the object below. Lines beginning with a '#' will be ignored,
|
||||||
# and an empty file will abort the edit. If an error occurs while saving this file will be
|
# and an empty file will abort the edit. If an error occurs while saving this file will be
|
||||||
# reopened with the relevant failures.
|
# reopened with the relevant failures.
|
||||||
@@ -203,11 +205,11 @@ Use `kubectl edit` to modify the size of a Cassandra StatefulSet.
|
|||||||
replicas: 3
|
replicas: 3
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Change the number of replicas to 4, and then save the manifest.
|
2. Change the number of replicas to 4, and then save the manifest.
|
||||||
|
|
||||||
The StatefulSet now contains 4 Pods.
|
The `StatefulSet` now contains 4 `Pod`s.
|
||||||
|
|
||||||
1. Get the Cassandra StatefulSet to verify:
|
1. Get the Cassandra `StatefulSet` to verify:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl get statefulset cassandra
|
kubectl get statefulset cassandra
|
||||||
@@ -223,13 +225,13 @@ Use `kubectl edit` to modify the size of a Cassandra StatefulSet.
|
|||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
{{% capture cleanup %}}
|
{{% capture cleanup %}}
|
||||||
Deleting or scaling a StatefulSet down does not delete the volumes associated with the StatefulSet. This ensures safety first: your data is more valuable than an auto purge of all related StatefulSet resources.
|
Deleting or scaling a `StatefulSet` down does not delete the volumes associated with the `StatefulSet`. This ensures safety first: your data is more valuable than an auto purge of all related StatefulSet resources.
|
||||||
|
|
||||||
{{< warning >}}
|
{{< warning >}}
|
||||||
**Warning:** Depending on the storage class and reclaim policy, deleting the Persistent Volume Claims may cause the associated volumes to also be deleted. Never assume you’ll be able to access data if its volume claims are deleted.
|
**Warning:** Depending on the storage class and reclaim policy, deleting the `PersistentVolumeClaim`s may cause the associated volumes to also be deleted. Never assume you’ll be able to access data if its volume claims are deleted.
|
||||||
{{< /warning >}}
|
{{< /warning >}}
|
||||||
|
|
||||||
1. Run the following commands to delete everything in a `StatefulSet`:
|
1. Run the following commands (chained together into a single command) to delete everything in the Cassandra `StatefulSet`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
grace=$(kubectl get po cassandra-0 -o=jsonpath='{.spec.terminationGracePeriodSeconds}') \
|
grace=$(kubectl get po cassandra-0 -o=jsonpath='{.spec.terminationGracePeriodSeconds}') \
|
||||||
@@ -241,7 +243,7 @@ Deleting or scaling a StatefulSet down does not delete the volumes associated wi
|
|||||||
|
|
||||||
1. Run the following command to delete the Cassandra `Service`.
|
1. Run the following command to delete the Cassandra `Service`.
|
||||||
|
|
||||||
```
|
```shell
|
||||||
kubectl delete service -l app=cassandra
|
kubectl delete service -l app=cassandra
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -249,10 +251,9 @@ Deleting or scaling a StatefulSet down does not delete the volumes associated wi
|
|||||||
|
|
||||||
{{% capture whatsnext %}}
|
{{% capture whatsnext %}}
|
||||||
|
|
||||||
* Learn how to [Scale a StatefulSet](/docs/tasks/run-application/scale-stateful-set/).
|
* Learn how to [Scale a `StatefulSet`](/docs/tasks/run-application/scale-stateful-set/).
|
||||||
* Learn more about the [KubernetesSeedProvider](https://github.com/kubernetes/examples/blob/master/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java)
|
* Learn more about the [`KubernetesSeedProvider`](https://github.com/kubernetes/examples/blob/master/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java)
|
||||||
* See more custom [Seed Provider Configurations](https://git.k8s.io/examples/cassandra/java/README.md)
|
* See more custom [Seed Provider Configurations](https://git.k8s.io/examples/cassandra/java/README.md)
|
||||||
|
|
||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user