Skip to content

Commit

Permalink
Sanitize client config object names and create a script to deploy on …
Browse files Browse the repository at this point in the history
…GKE multi cluster [K8SSAND-931] (k8ssandra#158)

* Sanitize client config object names and create a script to deploy on GKE multi cluster

* Remove the reliance on kubectx and remove the k8ssandra cluster creation from the script
  • Loading branch information
adejanovski authored Sep 29, 2021
1 parent 1bdc888 commit 26c6770
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aux-config/default/cass-operator/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace: default
resources:
- github.com/k8ssandra/cass-operator/config/default?ref=v1.8.0-rc.1
- github.com/k8ssandra/cass-operator/config/default?ref=v1.8.0-rc.2
# namePrefix: cass-operator- # Can be removed in this case because cass-operator already has a namePrefix defined in the repo.
84 changes: 84 additions & 0 deletions docs/install/deploy-gke-multi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
#
# As a prerequisite, cluster1 and cluster2 need to have a firewall rules allowing
# communications between their Pods CIDRs on ports 7000/7001 (Gossip) and 8080 (management API)
#
# Change the following variables to match your setup
# cluster1=k8ssandra-testing-dc1
# zone1=us-central1-c
# cluster2=k8ssandra-testing-dc2
# zone2=us-west1-a
# gcp_project=community-ecosystem


# Add kubeconfig entries for both clusters
gcloud container clusters get-credentials $cluster1 --zone $zone1 --project $gcp_project
gcloud container clusters get-credentials $cluster2 --zone $zone2 --project $gcp_project

# Install cert manager on both clusters
kubectl config use-context gke_${gcp_project}_${zone1}_${cluster1}
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml
kubectl config use-context gke_${gcp_project}_${zone2}_${cluster2}
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml

# Install the k8ssandra control plane
kubectl config use-context gke_${gcp_project}_${zone1}_${cluster1}
kustomize build aux-config/control_plane | kubectl apply -f -

# Install the k8ssandra data plane
kubectl config use-context gke_${gcp_project}_${zone2}_${cluster2}
kustomize build aux-config/data_plane | kubectl apply -f -

# Create the client config
export KUBECONFIG=./build/kubeconfigs/${cluster1}.yaml
gcloud container clusters get-credentials ${cluster1} --zone ${zone1} --project ${gcp_project}
export KUBECONFIG=./build/kubeconfigs/${cluster2}.yaml
gcloud container clusters get-credentials ${cluster2} --zone ${zone2} --project ${gcp_project}
unset KUBECONFIG

scripts/create-clientconfig.sh --src-kubeconfig build/kubeconfigs/${cluster2}.yaml --dest-kubeconfig build/kubeconfigs/${cluster1}.yaml --in-cluster-kubeconfig build/kubeconfigs/${cluster2}.yaml --output-dir clientconfig

# Restart the k8ssandra-operator pod on the control-plane
kubectl config use-context gke_${gcp_project}_${zone1}_${cluster1}
kubectl delete pod -l control-plane=k8ssandra-operator

# Create a K8ssandraCluster
echo "You can create a K8ssandra cluster by running the following command, after adjusting it to match your requirements:
cat <<EOF | kubectl apply -f -
apiVersion: k8ssandra.io/v1alpha1
kind: K8ssandraCluster
metadata:
name: demo
spec:
cassandra:
cluster: demo
serverVersion: "4.0.0"
serverImage: k8ssandra/cass-management-api:4.0.0-v0.1.29
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
config:
jvmOptions:
heapSize: 512M
datacenters:
- metadata:
name: dc1
size: 3
stargate:
size: 1
heapSize: 256M
- metadata:
name: dc2
k8sContext: gke_${gcp_project}_${zone2}_${cluster2}
size: 3
stargate:
size: 1
heapSize: 256M
EOF
"
5 changes: 3 additions & 2 deletions scripts/create-clientconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ users:
token: $sa_token
EOF

output_secret="$src_context-config"
output_secret=$(echo "$src_context-config" | tr '_' '-')
echo "Creating secret $output_secret"

kubectl $dest_kubeconfig_opt $dest_context_opt $namespace_opt delete secret $output_secret || true
kubectl $dest_kubeconfig_opt $dest_context_opt $namespace_opt create secret generic $output_secret --from-file="$output_kubeconfig"

clientconfig_name="$src_context"
clientconfig_name=$(echo "$src_context" | tr '_' '-')
clientconfig_path="${output_dir}/${clientconfig_name}.yaml"
echo "Creating ClientConfig $clientconfig_path"
cat > "$clientconfig_path" <<EOF
Expand Down

0 comments on commit 26c6770

Please sign in to comment.