The xline-operator is a powerful tool designed to automate the process of bootstrapping, monitoring, snapshotting, and recovering an xline cluster on Kubernetes.
Xline operator requires a ClusterRole
with permission to create Kubernetes Custom Resource Definition (CRD).
In this example, the ClusterRole
specified in examples/cluster-role.yml
will bind to the default service account
through examples/cluster-role-binding.yml
.
You can change the binding if you want.
Apply RBAC:
$ kubectl apply -f examples/cluster-role.yml
clusterrole.rbac.authorization.k8s.io/xline-operator-role created
$ kubectl apply -f examples/cluster-role-binding.yml
clusterrolebinding.rbac.authorization.k8s.io/xline-operator-rolebinding created
Inspect RBAC:
$ kubectl describe clusterrole xline-operator-role
Name: xline-operator-role
Labels: <none>
Annotations: <none>
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
endpoints [] [] [*]
events [] [] [*]
persistentvolumeclaims [] [] [*]
pods [] [] [*]
services [] [] [*]
customresourcedefinitions.apiextensions.k8s.io [] [] [*]
statefulsets.apps [] [] [*]
cronjobs.batch [] [] [*]
xlineclusters.xlineoperator.xline.cloud [] [] [*]
Create a deployment:
$ kubectl apply -f examples/crd-deployment.yml
deployment.apps/my-xline-operator created
xline operator will automatically create a CRD:
$ kubectl get crd
NAME CREATED AT
xlineclusters.xlineoperator.xline.cloud -
Create an xline cluster:
$ kubectl apply -f examples/xline-cluster-example.yml
xlinecluster.xlineoperator.xline.cloud/my-xline-cluster created
Inspect xline pods:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-xline-cluster-0 1/1 Running 0 -
my-xline-cluster-1 1/1 Running 0 -
my-xline-cluster-2 1/1 Running 0 -
You can use kubectl scale
to resize the replicas of xline servers. xlinecluster
has a short name xc
$ kubectl scale xc my-xline-cluster --replicas=5
xlinecluster.xlineoperator.xline.cloud/my-xline-cluster scaled
Then we have 5 xline servers now!
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-xline-cluster-0 1/1 Running 0 -
my-xline-cluster-1 1/1 Running 0 -
my-xline-cluster-2 1/1 Running 0 -
my-xline-cluster-3 1/1 Running 0 -
my-xline-cluster-4 1/1 Running 0 -
Notice that you cannot scale your cluster size less than 3. The operator cannot work with less than 3 nodes.
$ kubectl scale xc my-xline-cluster --replicas=1
The XlineCluster "my-xline-cluster" is invalid: spec.size: Invalid value: 1: spec.size in body should be greater than or equal to 3
$ kubectl delete -f examples/xline-cluster-example.yml
You can use affinity
to specify which nodes the xline servers should be scheduled on or which nodes should not be.
Details about affinity
can be found
in Kubernetes documentation.
Create an xline cluster with affinity
:
$ kubectl apply -f examples/affinity-example.yml
The above example will create an xline cluster with affinity
that requires the xline servers to be scheduled on nodes
which have an xline pod before.
In other words, the xline cluster servers will be scheduled on the same node.
You can replace the topologyKey
with
some other key to schedule the xline servers on different nodes shared the same topologyKey
. You can also
use podAntiAffinity
to force the xline servers to be scheduled on different nodes.
Read the document CODE_OF_CONDUCT.md for more details.