This file walks through how to setup Solr under Kubernetes using Docker Desktop on Mac or Windows. The steps are as follows:
- Enable Kubernetes in Docker Desktop
- Install an Ingress Controller to reach the cluster from the outside
- Install the Solr Operator
- Create a Solr cluster
- Create a collection and index some documents
- Scale from 3 to 5 nodes
- Upgrade to a newer Solr version
- Install Kubernetes Dashboard (optional)
- Delete the solrCloud cluster
NOTE: This tutorial may show Unix-style paths
foo/bar/
, which Windows users may need to replace with backslash\
, depending on what Terminal you are using.
We assume you already have Docker Desktop installed. Docker Desktop for Mac and Windows already includes Kubernetes (k8s), but it is not enabled by default. Also, it is best to use the 'edge' channel to get the latest version of Kubernetes. Let's enable Kubernetes:
- Open the Docker 'Preferences' (Mac) or 'Settings' (Win) from the "Whale" icon:
- Tick the "Enable Kubernetes" checkbox
- Then wait for Kubernetes to initialize
- You may need to assign some more CPU and RAM to Docker for this tutorial, under the "Resources" tab in Settings.
- Check that it works from Terminal. Open a Terminal window and type
kubectl get all
- Install Helm, as we'll use it later. Short instructions:
Mac:brew install helm
Windows with Chocolatey:choco install -y kubernetes-helm
- Install cURL if you don't have it:
Mac:brew install curl
Windows with Chocolatey:choco install -y curl
- Install unzip if on Windows:
choco install -y unzip
If you got stuck with the short-hand commands above, here are detailed instructions for Windows 10 for how to use an elevated Powershell on Windows to install Chocolatey and to execute 'choco' commands.
-
Click the Windows menu and search for 'powershell'
-
Right-click on "Windows Powershell" and select "Run as administrator"
-
Install Chocolatey:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
-
Install helm, curl and unzip
choco install -y kubernetes-helm curl unzip
-
If you also want to run the latest 'edge' version of Docker Desktop, you can install it with choco
choco install -y docker-desktop --pre
Kubernetes services are by default only accessible from within the k8s cluster. To make them addressable from our laptop, we'll add an ingress controller.
-
Install the nginx ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml
-
Inspect that the ingress controller is running
kubectl get all --namespace ingress-nginx
-
Edit your 'hosts' file
The hosts file (
/etc/hosts
on Mac orc:\windows\system32\drivers\etc\hosts
on Windows) tells your computer what hostname maps to what IP address. We use this trick to route our solr cluster domain name to localhost for routing into k8s. Replace the 127.0.0.1 line with:127.0.0.1 localhost kubernetes.docker.internal default-example-solrcloud.ing.local.domain ing.local.domain default-example-solrcloud-0.ing.local.domain default-example-solrcloud-1.ing.local.domain default-example-solrcloud-2.ing.local.domain dinghy-ping.localhost
TIP: You need to edit the file as Administrator/root. On Windows a simple way to do this is to copy this command into the Administrative Powershell window:
notepad c:\windows\system32\drivers\etc\hosts
Once we have installed Solr to our k8s, this will allow us to address the nodes locally.
Now that we have the prerequisites setup, let us install Solr Operator which will let us easily manage a large Solr cluster:
-
Download the operator
Mac/Linux:
OPERATOR_VER=0.2.5 curl https://codeload.github.com/bloomberg/solr-operator/tar.gz/v$OPERATOR_VER | tar xz ln -s -f solr-operator-$OPERATOR_VER solr-operator
Windows CMD:
set OPERATOR_VER=0.2.5 curl -o solr-operator.zip https://codeload.github.com/bloomberg/solr-operator/zip/v%OPERATOR_VER% unzip solr-operator.zip ren solr-operator-%OPERATOR_VER% solr-operator
Windows Powershell:
Remove-Item Alias:curl $OPERATOR_VER="0.2.5" curl -o solr-operator.zip https://codeload.github.com/bloomberg/solr-operator/zip/v$OPERATOR_VER unzip solr-operator.zip ren solr-operator-$OPERATOR_VER solr-operator
-
Install the Zookeeper operator
kubectl apply -f solr-operator/example/dependencies/
-
Install the Solr operator
We'll also specify ingressBaseDomain to match our ingressController
helm install --set-string ingressBaseDomain=ing.local.domain solr-operator solr-operator/helm/solr-operator
-
Inspect status
kubectl get all
To start a Solr cluster, we will create a descriptor for the Solr Operator that will tell it what version of solr to install, and how many nodes, with how much memory etc.
-
Create a spec for a 3-node cluster
We use Solr 8.3 with 300m RAM each to fit in your memory. The file
k8s-cluster.yaml
already exists in the tutorial:apiVersion: solr.bloomberg.com/v1beta1 kind: SolrCloud metadata: name: example spec: replicas: 3 solrImage: tag: "8.3" solrJavaMem: "-Xms300m -Xmx300m"
-
Install Solr from that spec
kubectl apply -f k8s-cluster.yaml
-
Check status of the deploy
Run the below command multiple times in a row to follow the creation of the pods
kubectl get solrclouds
-
Open a web browser to see a solr node
This requires the ingress controller to work properly. Note that this is on the service level, so will round-robin between the nodes.
Open the nodes tab of Admin UI.
You could create collections as normal through the collections API or the Admin UI. But we'll use the Operator's built in collection creation option, which will model each collection as a k8s resource (CRD).
-
Create a collection specification yaml (there is already a file
k8s-collection.yaml
):apiVersion: solr.bloomberg.com/v1beta1 kind: SolrCollection metadata: name: mycoll spec: solrCloud: example collection: mycoll autoAddReplicas: true routerName: compositeId numShards: 1 replicationFactor: 3 maxShardsPerNode: 2 collectionConfigName: "_default"
-
Execute the command and check in Admin UI that it succeeds
kubectl apply -f k8s-collection.yaml
-
Check in Admin UI that collection is created
Open http://default-example-solrcloud.ing.local.domain/solr/#/~cloud?view=graph
-
Index some documents
Mac/Linux:
curl -XPOST -H "Content-Type: application/json" \ -d '[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}]' \ http://default-example-solrcloud.ing.local.domain/solr/mycoll/update/
Windows CMD:
curl -XPOST -H "Content-Type: application/json" ^ -d "[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}]" ^ http://default-example-solrcloud.ing.local.domain/solr/mycoll/update/
Windows Powershell:
Remove-Item Alias:curl curl -XPOST -H "Content-Type: application/json" ` -d "[{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}]" ` http://default-example-solrcloud.ing.local.domain/solr/mycoll/update/
So we wish to add more capacity. Scaling the cluster is a breeze. You can keep refreshing the Admin UI Nodes or Graph screen while the scaling is being done to see the progress.
-
Run the scale command
kubectl scale --replicas=5 solrcloud/example
-
Check status at the end
kubectl get solrclouds
So we wish to upgrade from Solr version 8.3.1 to Solr 8.4. The procedure is exactly the same as for the first install of the cluster. Kubernetes takes care of stopping one pod (solr node) at a time, upgrading to the new Solr version.
-
Edit the solrCloud configuration to specify the new version
Open The file
k8s-cluster.yaml
in an editor an change the 'tag' from "8.3" to "8.4". Also change 'replicas' from 3 to 5. It should now look like this:apiVersion: solr.bloomberg.com/v1beta1 kind: SolrCloud metadata: name: example spec: replicas: 5 solrImage: tag: "8.4" solrJavaMem: "-Xms300m -Xmx300m"
NOTE: Since we use the same name 'example' as the existing solr cluster, it will automatically do an upgrade instead of a new install
-
Apply the modified config
kubectl apply -f k8s-cluster.yaml
-
Watch the change in Solr Admin UI
Open the nodes tab of Admin UI and keep refreshing to see the changes.
-
Verify that the chance is complete by inspecting the 'solrclouds' CRD:
kubectl get solrclouds
If extra time
Kubernetes Dashboard is a web interface that gives a better overview of your k8s cluster than only running command-line commands. This step is optional, you don't need it if you're comfortable with the CLI.
-
Install the Dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
-
You need to authenticate with the dashboard. Get a token
Mac/Linux:
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Windows Powershell:
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | sls admin-user | ForEach-Object { $_ -Split '\s+' } | Select -First 1)
Copy the token from the last line
-
Start a kube-proxy in another Terminal window
Kube-proxy proxies localhost:8001 to inside Kubernetes cluster, so we can access the dashboard.
kubectl proxy
-
Open a browser to the dashboard (note, this is one long URL)
-
Log in to the Dashboard
Click 'Token' in the Dashboard UI and paste the token from last step (starting with 'ey...')
-
Browse around
Familiarize yourself with the Dashboard. You can read more about the dashboard in the Kubernetes Documentation
When done, you can delete the solr cluster with this command
kubectl delete solrcloud example
Try to delete the other resources you created, either using the Kubernetes Dashboard or the command line. Hint: kubectl get all
will list many resources and kubectl delete -f <url-or-file.yaml>
will delete resources.
You may also reset Kubernetes with a button 'Reset Kubernetes Cluster' in Docker Desktop Settings.