[go: nahoru, domu]

Skip to content

Commit

Permalink
bump version of C* driver, SDC changes for Astra
Browse files Browse the repository at this point in the history
  • Loading branch information
csplinter committed Aug 3, 2020
1 parent c686976 commit 0e6e18b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
78 changes: 51 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,30 @@ kubectl create ns spring-data-service
kubectl create ns gateway-service
```

### 3.c - Setup Cassandra Operator
Start the Cassandra operator
```
# create the storage class for the database
kubectl -n cass-operator apply -f deploy/storage-class.yml
### 3.c - Setup DataStax Astra or Cassandra Kubernetes Operator
#### DataStax Astra
Create a free tier database in [DataStax Astra](https://astra.datastax.com/) with keyspace name `betterbotz`

# apply the operator manifest
kubectl -n cass-operator apply -f https://raw.githubusercontent.com/DataStax-Academy/kubernetes-workshop-online/master/1-cassandra/11-install-cass-operator-v1.1.yaml
Download the secure connect bundle from the Astra UI ([docs](https://docs.datastax.com/en/astra/aws/doc/dscloud/astra/dscloudObtainingCredentials.html))

# start a single C* 4.0 node
kubectl -n cass-operator apply -f deploy/cassandra-4.0.0-1node.yml
Create secrets for the Astra username/password and secure connect bundle
```

Create the Kubernetes Secrets for database username and password
DB_USER=<astra-db-user>
DB_PASSWORD=<astra-db-password>
SECURE_CONNECT_BUNDLE_PATH=<path-to-secure-connect-bundle>
```
# get the username and password from the secret
DB_USER=$(kubectl -n cass-operator get secret cluster1-superuser -o yaml | grep username | cut -d " " -f 4 | base64 -d)
DB_PASSWORD=$(kubectl -n cass-operator get secret cluster1-superuser -o yaml | grep password | cut -d " " -f 4 | base64 -d)

# create k8s secrets for the services (skip cmd for Spring Boot service if using Astra)
```
kubectl -n spring-boot-service create secret generic db-secret --from-literal=username=$DB_USER --from-literal=password=$DB_PASSWORD
kubectl -n spring-data-service create secret generic db-secret --from-literal=username=$DB_USER --from-literal=password=$DB_PASSWORD
kubectl -n spring-boot-service create secret generic astracreds --from-file=secure-connect-bundle=$SECURE_CONNECT_BUNDLE_PATH
```

### 3.d - (Optional) Use DataStax Astra for Spring Boot Service

Create a free tier database in [DataStax Astra](https://astra.datastax.com/) with keyspace name `betterbotz`

Download the secure connect bundle from the Astra UI ([docs](https://docs.datastax.com/en/astra/aws/doc/dscloud/astra/dscloudObtainingCredentials.html))

Create secrets for the Astra username/password and secure connect bundle
```
kubectl -n spring-boot-service create secret generic db-secret --from-literal=username=<astra-db-user> --from-literal=password=<astra-db-pass>
kubectl -n spring-boot-service create secret generic astracreds --from-file=secure-connect-bundle=<path-to-secure-connect-bundle>
kubectl -n spring-data-service create secret generic db-secret --from-literal=username=$DB_USER --from-literal=password=$DB_PASSWORD
kubectl -n spring-data-service create secret generic astracreds --from-file=secure-connect-bundle=$SECURE_CONNECT_BUNDLE_PATH
```

Change [ConfigMap](deploy/spring-boot/spring-boot-service-configmap.yml) to use secure connect bundle
Change Spring Boot [ConfigMap](deploy/spring-boot/spring-boot-service-configmap.yml) to use secure connect bundle
```
apiVersion: v1
kind: ConfigMap
Expand All @@ -136,7 +123,18 @@ data:
astra.secure-connect-bundle: /app/astra/creds
```

Uncomment lines in [Deployment.yml](spring-boot-deployment.yml)
Change Spring Data [ConfigMap](deploy/spring-data/spring-data-service-configmap.yml) to use secure connect bundle
```
apiVersion: v1
kind: ConfigMap
metadata:
name: spring-data-service
data:
application.yml: |-
astra.secure-connect-bundle: /app/astra/creds
```

Uncomment the following lines in [Spring Boot Deployment.yml](deploy/spring-boot/spring-boot-deployment.yml) and [Spring Data Deployment.yml](deploy/spring-data/spring-data-deployment.yml)
```
volumes:
- name: astravol
Expand All @@ -152,6 +150,32 @@ volumeMounts:
readOnly: true
```

You're ready to go!

#### Cassandra Kubernetes Operator
Start the Cassandra operator
```
# create the storage class for the database
kubectl -n cass-operator apply -f deploy/storage-class.yml
# apply the operator manifest
kubectl -n cass-operator apply -f https://raw.githubusercontent.com/DataStax-Academy/kubernetes-workshop-online/master/1-cassandra/11-install-cass-operator-v1.1.yaml
# start a single C* 4.0 node
kubectl -n cass-operator apply -f deploy/cassandra-4.0.0-1node.yml
```

Create the Kubernetes Secrets for database username and password
```
# get the username and password from the secret
DB_USER=$(kubectl -n cass-operator get secret cluster1-superuser -o yaml | grep username | cut -d " " -f 4 | base64 -d)
DB_PASSWORD=$(kubectl -n cass-operator get secret cluster1-superuser -o yaml | grep password | cut -d " " -f 4 | base64 -d)
# create k8s secrets for the services (skip cmd for Spring Boot service if using Astra)
kubectl -n spring-boot-service create secret generic db-secret --from-literal=username=$DB_USER --from-literal=password=$DB_PASSWORD
kubectl -n spring-data-service create secret generic db-secret --from-literal=username=$DB_USER --from-literal=password=$DB_PASSWORD
```

### Running
Start the services
```
Expand Down
13 changes: 13 additions & 0 deletions deploy/spring-data/spring-data-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ spec:
labels:
app: spring-data-service
spec:
# enable for Astra
# volumes:
# - name: astravol
# secret:
# secretName: astracreds
# items:
# - key: secure-connect-bundle
# path: creds
containers:
- env:
- name: KUBERNETES_TRUST_CERTIFICATES
Expand All @@ -31,6 +39,11 @@ spec:
secretKeyRef:
name: db-secret
key: password
# enable for Astra
# volumeMounts:
# - name: astravol
# mountPath: "/app/astra"
# readOnly: true
image: csplinter/spring-data-service:1.0.0-SNAPSHOT
imagePullPolicy: Never
name: spring-data-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public CqlSessionBuilder configure(CqlSessionBuilder cqlSessionBuilder) {

@Override
protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
if (!astraSecureConnectBundle.equals("none")) {
if (astraSecureConnectBundle.equals("none")) {
return Arrays.asList(CreateKeyspaceSpecification
.createKeyspace(getKeyspaceName())
.ifNotExists(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ server.port: 8081
management.server.port: 8082

spring.data.rest.basePath: /api
spring.data.cassandra.keyspace-name: betterbotz
---
spring.profiles: docker
spring:
data:
cassandra:
port: 9042
contact-points: host.docker.internal
keyspace-name: betterbotz
local-datacenter: dc1
schema-action: create-if-not-exists
---
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<spring-data-rest.version>3.3.0.RELEASE</spring-data-rest.version>
<spring-cloud-kubernetes.version>1.1.3.RELEASE</spring-cloud-kubernetes.version>

<cassandra-java-driver.version>4.6.1</cassandra-java-driver.version>
<cassandra-java-driver.version>4.8.0</cassandra-java-driver.version>

<!-- Third Parties -->
<common-fileupload>1.3.3</common-fileupload>
Expand Down Expand Up @@ -127,6 +127,11 @@
<artifactId>java-driver-mapper-runtime</artifactId>
<version>${cassandra-java-driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>native-protocol</artifactId>
<version>1.4.11</version>
</dependency>

<!-- Rest API -->
<dependency>
Expand Down

0 comments on commit 0e6e18b

Please sign in to comment.