<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by John Sanda on Medium]]></title>
        <description><![CDATA[Stories by John Sanda on Medium]]></description>
        <link>https://medium.com/@john-sanda?source=rss-683e7d1684dd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*TNyuZgO7yQtXUih7nYP3cg.jpeg</url>
            <title>Stories by John Sanda on Medium</title>
            <link>https://medium.com/@john-sanda?source=rss-683e7d1684dd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:17:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@john-sanda/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My New Favorite Feature of Cass Operator]]></title>
            <link>https://john-sanda.medium.com/my-new-favorite-feature-of-cass-operator-98345dafe1cc?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/98345dafe1cc</guid>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 05:46:18 GMT</pubDate>
            <atom:updated>2020-11-26T05:46:18.903Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working with <a href="https://github.com/datastax/cass-operator">Cass Operator</a> a lot as part of my work on <a href="https://k8ssandra.io/">K8ssandra</a>. I have a new favorite feature that I want to discuss. That feature is the podTemplateSpec property of CassandraDatacenter.</p><p>The podTemplateSpec property is for advanced use cases. It is essentially a hook to customize the underlying StatefulSets that Cass Operator creates.</p><p>Let’s look at an example to illustrate how it can be put to use.</p><pre>apiVersion: cassandra.datastax.com/v1beta1<br>kind: CassandraDatacenter<br>metadata:<br>  name: dc1<br>spec:<br>  clusterName: demo<br>  serverType: cassandra<br>  serverVersion: 3.11.7<br>  managementApiAuth:<br>    insecure: {}<br>  size: 3<br>  <strong>podTemplateSpec:<br>    spec:<br>      initContainers:<br>        - name: echo-username<br>          image: busybox<br>          imagePullPolicy: IfNotPresent<br>          env:<br>            - name: USERNAME<br>              value: jsanda<br>          args:<br>          - /bin/sh<br>          - -c<br>          - echo -n &quot;USERNAME = $USERNAME&quot;<br>      containers: []</strong><br>  storageConfig:<br>    cassandraDataVolumeClaimSpec:<br>      storageClassName: standard<br>      accessModes:<br>      - ReadWriteOnce<br>      resources:<br>        requests:<br>          storage: 5Gi</pre><p>I declared an initContainer that simply echoes the value of the USERNAME environment variable.</p><p>Now let’s look at the .spec.template.spec property of the StatefulSet created by Cass Operator:</p><pre>$ kubectl -n deploy-reaper-test get sts demo-dc1-default-sts -o yaml</pre><pre>apiVersion: apps/v1<br>kind: StatefulSet<br>metadata:<br>  annotations:<br>    cassandra.datastax.com/resource-hash: soyJEGWaLENAD2p9wVn/+9AxakV5DGs8vk7y/JPrHWI=<br>  creationTimestamp: &quot;2020-11-26T03:42:06Z&quot;<br>  generation: 2<br>  labels:<br>    app.kubernetes.io/managed-by: cass-operator<br>    cassandra.datastax.com/cluster: demo<br>    cassandra.datastax.com/datacenter: dc1<br>    cassandra.datastax.com/rack: default<br>  name: demo-dc1-default-sts<br>  namespace: deploy-reaper-test<br>  ownerReferences:<br>  - apiVersion: cassandra.datastax.com/v1beta1<br>    blockOwnerDeletion: true<br>    controller: true<br>    kind: CassandraDatacenter<br>    name: dc1<br>    uid: 3f6b8600-148b-48f9-8ae8-a2166a0b6b0a<br>  resourceVersion: &quot;17320734&quot;<br>  selfLink: /apis/apps/v1/namespaces/deploy-reaper-test/statefulsets/demo-dc1-default-sts<br>  uid: 0679475f-357b-40d1-bf37-92c6af96e093<br>spec:<br>  podManagementPolicy: Parallel<br>  replicas: 3<br>  revisionHistoryLimit: 10<br>  selector:<br>    matchLabels:<br>      cassandra.datastax.com/cluster: demo<br>      cassandra.datastax.com/datacenter: dc1<br>      cassandra.datastax.com/rack: default<br>  serviceName: demo-dc1-service<br>  template:<br>    metadata:<br>      creationTimestamp: null<br>      labels:<br>        app.kubernetes.io/managed-by: cass-operator<br>        cassandra.datastax.com/cluster: demo<br>        cassandra.datastax.com/datacenter: dc1<br>        cassandra.datastax.com/node-state: Ready-to-Start<br>        cassandra.datastax.com/rack: default<br>    spec:<br>      affinity:<br>        podAntiAffinity:<br>          requiredDuringSchedulingIgnoredDuringExecution:<br>          - labelSelector:<br>              matchExpressions:<br>              - key: cassandra.datastax.com/cluster<br>                operator: Exists<br>              - key: cassandra.datastax.com/datacenter<br>                operator: Exists<br>              - key: cassandra.datastax.com/rack<br>                operator: Exists<br>            topologyKey: kubernetes.io/hostname<br>      containers:<br>      - env:<br>        - name: DS_LICENSE<br>          value: accept<br>        - name: DSE_AUTO_CONF_OFF<br>          value: all<br>        - name: USE_MGMT_API<br>          value: &quot;true&quot;<br>        - name: MGMT_API_EXPLICIT_START<br>          value: &quot;true&quot;<br>        - name: DSE_MGMT_EXPLICIT_START<br>          value: &quot;true&quot;<br>        image: datastax/cassandra-mgmtapi-3_11_7:v0.1.13<br>        imagePullPolicy: IfNotPresent<br>        lifecycle:<br>          preStop:<br>            exec:<br>              command:<br>              - wget<br>              - --output-document<br>              - /dev/null<br>              - --no-check-certificate<br>              - --post-data=&#39;&#39;<br>              - <a href="http://localhost:8080/api/v0/ops/node/drain">http://localhost:8080/api/v0/ops/node/drain</a><br>        livenessProbe:<br>          failureThreshold: 3<br>          httpGet:<br>            path: /api/v0/probes/liveness<br>            port: 8080<br>            scheme: HTTP<br>          initialDelaySeconds: 15<br>          periodSeconds: 15<br>          successThreshold: 1<br>          timeoutSeconds: 1<br>        name: cassandra<br>        ports:<br>        - containerPort: 9042<br>          name: native<br>          protocol: TCP<br>        - containerPort: 9142<br>          name: tls-native<br>          protocol: TCP<br>        - containerPort: 7000<br>          name: internode<br>          protocol: TCP<br>        - containerPort: 7001<br>          name: tls-internode<br>          protocol: TCP<br>        - containerPort: 7199<br>          name: jmx<br>          protocol: TCP<br>        - containerPort: 8080<br>          name: mgmt-api-http<br>          protocol: TCP<br>        - containerPort: 9103<br>          name: prometheus<br>          protocol: TCP<br>        - containerPort: 9160<br>          name: thrift<br>          protocol: TCP<br>        readinessProbe:<br>          failureThreshold: 3<br>          httpGet:<br>            path: /api/v0/probes/readiness<br>            port: 8080<br>            scheme: HTTP<br>          initialDelaySeconds: 20<br>          periodSeconds: 10<br>          successThreshold: 1<br>          timeoutSeconds: 1<br>        resources: {}<br>        terminationMessagePath: /dev/termination-log<br>        terminationMessagePolicy: File<br>        volumeMounts:<br>        - mountPath: /config<br>          name: server-config<br>        - mountPath: /var/log/cassandra<br>          name: server-logs<br>        - mountPath: /var/lib/cassandra<br>          name: server-data<br>        - mountPath: /etc/encryption/<br>          name: encryption-cred-storage<br>      - args:<br>        - /bin/sh<br>        - -c<br>        - tail -n+1 -F /var/log/cassandra/system.log<br>        image: busybox<br>        imagePullPolicy: Always<br>        name: server-system-logger<br>        resources:<br>          limits:<br>            cpu: 100m<br>            memory: 64M<br>          requests:<br>            cpu: 100m<br>            memory: 64M<br>        terminationMessagePath: /dev/termination-log<br>        terminationMessagePolicy: File<br>        volumeMounts:<br>        - mountPath: /var/log/cassandra<br>          name: server-logs<br>      dnsPolicy: ClusterFirst<br>      initContainers:<br>      - env:<br>        - name: CONFIG_FILE_DATA<br>          value: &#39;{&quot;cassandra-yaml&quot;:{},&quot;cluster-info&quot;:{&quot;name&quot;:&quot;demo&quot;,&quot;seeds&quot;:&quot;demo-seed-service&quot;},&quot;datacenter-info&quot;:{&quot;graph-enabled&quot;:0,&quot;name&quot;:&quot;dc1&quot;,&quot;solr-enabled&quot;:0,&quot;spark-enabled&quot;:0}}&#39;<br>        - name: POD_IP<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: status.podIP<br>        - name: HOST_IP<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: status.hostIP<br>        - name: USE_HOST_IP_FOR_BROADCAST<br>          value: &quot;false&quot;<br>        - name: RACK_NAME<br>          value: default<br>        - name: PRODUCT_VERSION<br>          value: 3.11.7<br>        - name: PRODUCT_NAME<br>          value: cassandra<br>        - name: DSE_VERSION<br>          value: 3.11.7<br>        image: datastax/cass-config-builder:1.0.3<br>        imagePullPolicy: IfNotPresent<br>        name: server-config-init<br>        resources:<br>          limits:<br>            cpu: &quot;1&quot;<br>            memory: 256M<br>          requests:<br>            cpu: &quot;1&quot;<br>            memory: 256M<br>        terminationMessagePath: /dev/termination-log<br>        terminationMessagePolicy: File<br>        volumeMounts:<br>        - mountPath: /config<br>          name: server-config<br>      <strong>- args:<br>        - /bin/sh<br>        - -c<br>        - echo -n &quot;USERNAME = $USERNAME&quot;<br>        env:<br>        - name: USERNAME<br>          value: jsanda<br>        image: busybox<br>        imagePullPolicy: IfNotPresent<br>        name: echo<br>        resources: {}<br>        terminationMessagePath: /dev/termination-log<br>        terminationMessagePolicy: File</strong><br>      restartPolicy: Always<br>      schedulerName: default-scheduler<br>      securityContext: {}<br>      serviceAccount: default<br>      serviceAccountName: default<br>      terminationGracePeriodSeconds: 120<br>      volumes:<br>      - emptyDir: {}<br>        name: server-config<br>      - emptyDir: {}<br>        name: server-logs<br>      - name: encryption-cred-storage<br>        secret:<br>          defaultMode: 420<br>          secretName: dc1-keystore<br>  updateStrategy:<br>    rollingUpdate:<br>      partition: 0<br>    type: RollingUpdate<br>  volumeClaimTemplates:<br>  - apiVersion: v1<br>    kind: PersistentVolumeClaim<br>    metadata:<br>      creationTimestamp: null<br>      labels:<br>        app.kubernetes.io/managed-by: cass-operator<br>        cassandra.datastax.com/cluster: demo<br>        cassandra.datastax.com/datacenter: dc1<br>        cassandra.datastax.com/rack: default<br>      name: server-data<br>    spec:<br>      accessModes:<br>      - ReadWriteOnce<br>      resources:<br>        requests:<br>          storage: 5Gi<br>      storageClassName: standard<br>      volumeMode: Filesystem<br>    status:<br>      phase: Pending</pre><p>My echo initContainer is included in the output. Every StatefulSet that Cass Operator creates will include the following containers:</p><ul><li>server-config-init initContainer</li><li>cassandra container</li><li>server-system-logger container</li></ul><p>The podTemplateSpec property allowed me to modify the StatefulSet to include the echo initContainer. Pretty cool!</p><p>The echo initContainer is a bit contrived, but it provides a blueprint for a way to apply advanced configurations with Cass Operator. In my next post I will go through a real world example. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98345dafe1cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Watch Multiple Namespaces With Cass Operator]]></title>
            <link>https://medium.com/swlh/watch-multiple-namespaces-with-cass-operator-81d04a5af741?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/81d04a5af741</guid>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[operators]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Wed, 22 Jul 2020 02:58:16 GMT</pubDate>
            <atom:updated>2020-07-22T21:30:16.859Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we will take a look at how to configure and deploy <a href="https://github.com/datastax/cass-operator">Cass Operator</a> so that it can watch multiple namespaces. We will make the necessary RBAC changes so that the operator can manage CassandraDatacenters in the watched namespaces.</p><p><a href="https://medium.com/faun/kubernetes-rbac-use-one-role-in-multiple-namespaces-d1d08bb08286">This post</a> served as a great resource as I started looking into how to do this.</p><p>Here is version info of the Kubernetes cluster that I used for testing:</p><pre>$ kubectl version<br>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;16&quot;, GitVersion:&quot;v1.16.9&quot;, GitCommit:&quot;a17149e1a189050796ced469dbd78d380f2ed5ef&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-04-16T11:44:51Z&quot;, GoVersion:&quot;go1.13.9&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}<br>Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;16+&quot;, GitVersion:&quot;v1.16.11-gke.5&quot;, GitCommit:&quot;baccd25d44f1a0d06ad3190eb508784efbb990a5&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-06-25T22:55:26Z&quot;, GoVersion:&quot;go1.13.9b4&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}</pre><h3>Background</h3><p>Someone in the community created a <a href="https://github.com/datastax/cass-operator/issues/115">ticket</a> about problems with webhook validation that occur when watching multiple namespaces. <a href="https://github.com/datastax/cass-operator/pull/173">This PR</a> resolves the issues raised in the ticket and should be included in the 1.4.0 release of Cass Operator.</p><p>You can deploy Cass Operator either by directly applying resource manifests or by installing the Helm chart. We are going to use the former approach in this post. The latest release of Cass Operator at the time of this writing is 1.3.0. Since the changes we need were just merged and not yet part of a release, we will have to install from master. We would typically use a command like the following:</p><pre>kubectl create -f <a href="https://raw.githubusercontent.com/datastax/cass-operator/bac509a81b6339219fe3fc313dbf384653563c59/docs/user/cass-operator-manifests-v1.16.yaml">https://raw.githubusercontent.com/datastax/cass-operator/bac509a81b6339219fe3fc313dbf384653563c59/docs/user/cass-operator-manifests-v1.16.yaml</a></pre><p>We want to download the manifests since we need to make modification to them. Download them as follows:</p><pre>$ wget <a href="https://raw.githubusercontent.com/datastax/cass-operator/bac509a81b6339219fe3fc313dbf384653563c59/docs/user/cass-operator-manifests-v1.16.yaml">https://raw.githubusercontent.com/datastax/cass-operator/bac509a81b6339219fe3fc313dbf384653563c59/docs/user/cass-operator-manifests-v1.16.yaml</a></pre><h3>Create Namespaces</h3><p>We will configure Cass Operator to watch and manage resources in two namespaces — dev1 and dev2. We need to add the following to the manifests file:</p><pre>---<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: dev1<br>---<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: dev2</pre><h3>Change the Role</h3><p>Next, we need to change the Role shown below:</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br><strong>kind: Role</strong><br>metadata:<br>  name: cass-operator<br>  namespace: cass-operator<br>rules:<br>- apiGroups:<br>  - &quot;&quot;<br>  resources:<br>  - pods<br>  - services<br>  - endpoints<br>  - persistentvolumeclaims<br>  - events<br>  - configmaps<br>  - secrets<br>  verbs:<br>  - &#39;*&#39;<br>- apiGroups:<br>  - &quot;&quot;<br>  resources:<br>  - namespaces<br>  verbs:<br>  - get<br>- apiGroups:<br>  - apps<br>  resources:<br>  - deployments<br>  - daemonsets<br>  - replicasets<br>  - statefulsets<br>  verbs:<br>  - &#39;*&#39;<br>- apiGroups:<br>  - monitoring.coreos.com<br>  resources:<br>  - servicemonitors<br>  verbs:<br>  - get<br>  - create<br>- apiGroups:<br>  - apps<br>  resourceNames:<br>  - cass-operator<br>  resources:<br>  - deployments/finalizers<br>  verbs:<br>  - update<br>- apiGroups:<br>  - datastax.com<br>  resources:<br>  - &#39;*&#39;<br>  verbs:<br>  - &#39;*&#39;<br>- apiGroups:<br>  - policy<br>  resources:<br>  - poddisruptionbudgets<br>  verbs:<br>- apiGroups:<br>  - cassandra.datastax.com<br>  resources:<br>  - &#39;*&#39;<br>  verbs:<br>  - &#39;*&#39;<br>- apiGroups:<br>  - batch<br>  resources:<br>  - &#39;*&#39;<br>  verbs:<br>  - &#39;*&#39;</pre><p>This Role declares what actions or operations the operator can perform on various resources. We are going to make one small modification and change the kind from Role to ClusterRole:</p><pre>kind: ClusterRole</pre><h3>Add RoleBindings</h3><p>Next, let’s look at the RoleBinding manifest:</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: cass-operator<br>  namespace: cass-operator<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: Role<br>  name: cass-operator<br>subjects:<br>- kind: ServiceAccount<br>  name: cass-operator</pre><p>The RoleBinding binds the operator ServiceAccount to the Role. Note that the binding applies only to the cass-operator namespace. We are going to add two RoleBindings:</p><pre>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: cass-operator-dev1<br>  <strong>namespace: dev1</strong><br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: cass-operator<br>subjects:<br>- kind: ServiceAccount<br>  name: cass-operator<br>  namespace: cass-operator<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: cass-operator-dev2<br>  <strong>namespace: dev2</strong><br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: cass-operator<br>subjects:<br>- kind: ServiceAccount<br>  name: cass-operator<br>  namespace: cass-operator</pre><p>Notice that the RoleBindings are for the dev1 and dev2 namespaces.</p><p>For my testing I am only deploying CassandraDatacenters into the dev1 and dev2 namespaces. Given this, I could use a more restrictive Role for the cass-operator namespace since I am only using it to deploy the operator. While this is an additional change worth considering, I did not have enough time to fully test it for this post.</p><p>Before moving onto the next resource manifest, it is worth taking a moment to consider the use here of RoleBindings vs ClusterRoleBindings. The motivation of using a RoleBinding is that it is more restrictive. It only has an effect within a given namespace. A ClusterRoleBinding on the other hand is effective across the entire cluster.</p><h3>Update the Deployment</h3><p>Now we need to turn our attention to the Deployment manifest:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: cass-operator<br>  namespace: cass-operator<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      name: cass-operator<br>  template:<br>    metadata:<br>      labels:<br>        name: cass-operator<br>    spec:<br>      containers:<br>      - env:<br>        <strong>- name: WATCH_NAMESPACE<br>          valueFrom:<br>            fieldRef:<br>              fieldPath: metadata.namespace</strong><br>        - name: POD_NAME<br>          valueFrom:<br>            fieldRef:<br>              fieldPath: metadata.name<br>        - name: OPERATOR_NAME<br>          value: cass-operator<br>        - name: SKIP_VALIDATING_WEBHOOK<br>          value: &quot;FALSE&quot;<br>        <strong>image: datastax/cass-operator:1.3.0</strong><br>        imagePullPolicy: IfNotPresent<br>        livenessProbe:<br>          exec:<br>            command:<br>            - pgrep<br>            - .*operator<br>          failureThreshold: 3<br>          initialDelaySeconds: 5<br>          periodSeconds: 5<br>          timeoutSeconds: 5<br>        name: cass-operator<br>        readinessProbe:<br>          exec:<br>            command:<br>            - stat<br>            - /tmp/operator-sdk-ready<br>          failureThreshold: 1<br>          initialDelaySeconds: 5<br>          periodSeconds: 5<br>          timeoutSeconds: 5<br>        securityContext:<br>          allowPrivilegeEscalation: false<br>          readOnlyRootFilesystem: true<br>          runAsGroup: 65534<br>          runAsUser: 65534<br>        volumeMounts:<br>        - mountPath: /tmp/k8s-webhook-server/serving-certs<br>          name: cass-operator-certs-volume<br>          readOnly: false<br>        - mountPath: /tmp/<br>          name: tmpconfig-volume<br>          readOnly: false<br>      serviceAccountName: cass-operator<br>      volumes:<br>      - emptyDir:<br>          medium: Memory<br>        name: tmpconfig-volume<br>      - name: cass-operator-certs-volume<br>        secret:<br>          secretName: cass-operator-webhook-config</pre><p>First, we need to update the WATCH_NAMESPACE environment variable so that it specifies the dev1 and dev2 namespaces:</p><pre>- env:<br>  - name: WATCH_NAMESPACE<br>    value: dev1,dev2</pre><p>Note that the image references the latest released of the operator, 1.3.0:</p><pre>image: datastax/cass-operator:1.3.0</pre><p>As previously discussed, we need to use a more recent, unreleased version. The CI for the cass-operator project pushes images to the GitHub package registry, which does not allow anonymous access. We need to use GitHub credentials in order to pull images. I will walk through steps for using a personal access token.</p><p>First, create a token (if you do not already have one) following the steps described <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">here</a>. Make sure that you grant the read:packages scope to the token as shown in this screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*DkGvvf9uXjZDgu9wNhYH4Q.png" /></figure><p>Next, create a secret:</p><pre>kubectl create secret docker-registry github-docker-registry --docker-username=$GITHUB_USERNAME --docker-password=$GITHUB_TOKEN --docker-server=docker.pkg.github.com --dry-run -o yaml</pre><p>Note that the secret does not actually get created since we used the dry-run option. The output should look similar to this:</p><pre>apiVersion: v1<br>data:<br>  .dockerconfigjson: eyJhdXRocyI6eyJkb2NrZXIucGtmLmdpdGh1Yi4jb20iOnsidXNlcm5hbWUiOiJqc2FuZGEiLCJkYXNzd29yZCI6IjhhZDc1NTM3ZmM5YZNlOTVkZTgyNmFiZBYxNzgzODMxZDYwZDJmNzkiLCJhdXRoIjoiYW5OaGJtUmhPamhoWkRjMU5UTTNabU01WVdObE9UVmtaVGd5Tm3GaVpEWXhOemd8T0RNeFpEWXdaREptTnprPTJ9fX0=<br>kind: Secret<br>metadata:<br>  creationTimestamp: null<br>  name: github-docker-registry<br>type: kubernetes.io/dockerconfigjson</pre><p>We will add the output to the manifests file.</p><p>Lastly, change the image in the Deployment to be:</p><pre>image: docker.pkg.github.com/datastax/cass-operator/operator:bac509a81b6339219fe3fc313dbf384653563c59</pre><p>Admittedly, that is a bit cumbersome. Keep in mind though that these extra steps are only necessary because we are using an unreleased version of Cass Operator. I went ahead and pushed the image to my Docker Hub repo. If you want to avoid these extra steps, you can alternatively use the following:</p><pre>image: jsanda/cass-operator:bac509a81b6339219fe3fc313dbf384653563c59</pre><h3>Deploy the Operator</h3><p>You can view my full, updated manifests in <a href="https://gist.github.com/jsanda/07ef74f0f19edacfe396560a6328bd7e">this gist</a>. With the manifest changes in place go ahead and run:</p><pre>kubectl create -f cass-operator-manifests-v1.16.yaml</pre><p>The output should look like this:</p><pre>$ kubectl create -f manifests.yaml<br>namespace/cass-operator created<br>namespace/dev1 created<br>namespace/dev2 created<br>serviceaccount/cass-operator created<br>secret/cass-operator-webhook-config created<br>secret/github-docker-registry created<br>customresourcedefinition.apiextensions.k8s.io/cassandradatacenters.cassandra.datastax.com created<br>clusterrole.rbac.authorization.k8s.io/cass-operator-cluster-role created<br>clusterrolebinding.rbac.authorization.k8s.io/cass-operator created<br>clusterrole.rbac.authorization.k8s.io/cass-operator created<br>rolebinding.rbac.authorization.k8s.io/cass-operator created<br>rolebinding.rbac.authorization.k8s.io/cass-operator-dev1 created<br>rolebinding.rbac.authorization.k8s.io/cass-operator-dev2 created<br>service/cassandradatacenter-webhook-service created<br>deployment.apps/cass-operator created<br>validatingwebhookconfiguration.admissionregistration.k8s.io/cassandradatacenter-webhook-registration created</pre><h3>Wrap Up</h3><p>I hope this post serves as a good starting point to show you how to configure Cass Operator to watch multiple namespaces. When the Helm chart gets updated, installing and configuring the operator to watch multiple namespaces should be much more streamlined than what I have described.</p><p>There may be situations where you do not want an operator per namespace. A cluster-wide deployment on the other hand, requires elevated security privileges. It might also have negative performance implications if the operator is managing a lot of resources. The approach outlined in this post provides a nice middle ground.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81d04a5af741" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/watch-multiple-namespaces-with-cass-operator-81d04a5af741">Watch Multiple Namespaces With Cass Operator</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Affinity between Cassandra and Kubernetes]]></title>
            <link>https://john-sanda.medium.com/create-affinity-between-cassandra-and-kubernetes-5b2f72d23293?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b2f72d23293</guid>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 03:28:10 GMT</pubDate>
            <atom:updated>2019-08-12T03:28:10.567Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p9rU0vCV8MW-AcUg.jpeg" /></figure><p>In my <a href="https://medium.com/@john.sanda/deploying-cassandra-in-kubernetes-with-casskop-1f721586825b">previous post</a>, we looked at how to deploy Cassandra clusters in Kubernetes using <a href="https://github.com/Orange-OpenSource/cassandra-k8s-operator">CassKop</a>. CassKop makes it easy to configure different topologies for Cassandra. In this post we continue with the theme of topology configuration. We will explore how we can leverage CassKop to make sure Cassandra pods run on particular Kubernetes nodes as well as to make sure pods run in specific availability zones. CassKop makes this possible by using <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/">labels</a> and <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/">affinity rules</a>.</p><p>Labels in Kubernetes are key/value pairs that can be added to objects such as pods, services, and even the nodes on which pods run. Labels help organize, select, and filter objects in a Kubernetes cluster.</p><p>Affinity rules are scheduling rules that help determine on what nodes pods <em>should</em> or <em>must</em> run. Conversely anti-affinity rules are scheduling rules that help determine on what nodes pods <em>should not</em> or m<em>ust not</em> run. For a more detailed overview, see the <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/">official docs</a>.</p><p>For cloud-based deployments of Cassandra it is common to organize racks by availability zone. This is done to improve availability and fault tolerance. For example, let’s say we have a nine node cluster spread across three racks, with each rack in a different availability zone. Let’s also suppose that the application keyspace(s) use relpication_factor = 3. This gives us a full set of replicas per rack. The cluster can withstand the loss of an entire availability zone and still maintain strong consistency.</p><p>With all that in mind, onto some examples!</p><h3>Soft Anti-affinity</h3><p>We will start with an easy example and work through progressively through more complex ones. This first example demonstrates a <em>should </em>or <em>soft </em>anti-affinity rule.</p><pre># soft-anti-affinity.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: soft-anti-affinity<br>  labels:<br>    cluster: soft-anti-affinity<br>spec:<br>  nodesPerRacks: 3<br>  resources:<br>    requests:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi<br>    limits:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi</pre><p><strong>Note:</strong> For this and the next example, I am using a three-node Kubernetes cluster that is running in a single availability zone.</p><p>Create the CassandraCluster with:</p><pre>$ kubectl apply -f soft-anti-affinity.yaml</pre><p>As discussed in my <a href="https://medium.com/@john.sanda/deploying-cassandra-in-kubernetes-with-casskop-1f721586825b">previous article</a>, CassKop creates a StatefulSet which in turn will create and manage the Cassandra pods:</p><pre>$ kubectl get statefulset -l cassandracluster=soft-anti-affinity<br>NAME                       READY   AGE<br>soft-anti-affinity-dc1-rack1   3/3     16m</pre><p>Let’s take a closer look at the StatefulSet soft-ant-affinity-dc1-rack1:</p><pre>$ kubectl get statefulset soft-anti-affinity-dc1-rack1 -o yaml<br>apiVersion: apps/v1<br>kind: StatefulSet<br>metadata:<br>  creationTimestamp: &quot;2019-08-10T03:04:32Z&quot;<br>  generation: 1<br>  labels:<br>    app: cassandracluster<br>    cassandracluster: soft-anti-affinity<br>    cassandraclusters.db.orange.com.dc: dc1<br>    cassandraclusters.db.orange.com.rack: rack1<br>    cluster: soft-anti-affinity<br>    dc-rack: dc1-rack1<br>  name: soft-anti-affinity-dc1-rack1<br>  namespace: default<br>  ownerReferences:<br>  - apiVersion: db.orange.com/v1alpha1<br>    controller: true<br>    kind: CassandraCluster<br>    name: soft-anti-affinity<br>    uid: 9373658d-bb1b-11e9-8455-42010a8e0041<br>  resourceVersion: &quot;14661&quot;<br>  selfLink: /apis/apps/v1/namespaces/default/statefulsets/soft-anti-affinity-dc1-rack1<br>  uid: 939d5e1f-bb1b-11e9-8455-42010a8e0041<br>spec:<br>  podManagementPolicy: OrderedReady<br>  replicas: 3<br>  revisionHistoryLimit: 10<br>  selector:<br>    matchLabels:<br>      app: cassandracluster<br>      cassandracluster: soft-anti-affinity<br>      cassandraclusters.db.orange.com.dc: dc1<br>      cassandraclusters.db.orange.com.rack: rack1<br>      cluster: soft-anti-affinity<br>      dc-rack: dc1-rack1<br>  serviceName: soft-anti-affinity<br>  <strong>template:</strong><br>    metadata:<br>      creationTimestamp: null<br>      <strong>labels:<br>        app: cassandracluster<br>        cassandracluster: soft-anti-affinity<br>        cassandraclusters.db.orange.com.dc: dc1<br>        cassandraclusters.db.orange.com.rack: rack1<br>        cluster: soft-anti-affinity<br>        dc-rack: dc1-rack1</strong><br>    spec:<br>      <strong>affinity:<br>        nodeAffinity: {}<br>        podAntiAffinity:<br>          preferredDuringSchedulingIgnoredDuringExecution:<br>          - podAffinityTerm:<br>              labelSelector:<br>                matchLabels:<br>                  app: cassandracluster<br>                  cassandracluster: soft-anti-affinity<br>                  cluster: soft-anti-affinity<br>              topologyKey: kubernetes.io/hostname<br>            weight: 100</strong><br>      containers:<br>      - env:<br>        - name: CASSANDRA_MAX_HEAP<br>          value: 125M<br>        - name: CASSANDRA_SEEDS<br>          value: soft-anti-affinity-dc1-rack1-0.soft-anti-affinity.default,soft-anti-affinity-dc1-rack1-1.soft-anti-affinity.default,soft-anti-affinityr-dc1-rack1-2.soft-anti-affinity.default<br>        - name: CASSANDRA_CLUSTER_NAME<br>          value: soft-anti-affinity<br>        - name: CASSANDRA_AUTO_BOOTSTRAP<br>          value: &quot;true&quot;<br>        - name: CASSANDRA_AUTHENTICATOR<br>          value: PasswordAuthenticator<br>        - name: CASSANDRA_AUTHORIZER<br>          value: CassandraAuthorizer<br>        - name: POD_IP<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: status.podIP<br>        - name: POD_NAME<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: metadata.name<br>        - name: SERVICE_NAME<br>          value: soft-anti-affinity-dc1-rack1<br>        - name: CASSANDRA_GC_STDOUT<br>          value: &quot;false&quot;<br>        - name: CASSANDRA_NUM_TOKENS<br>          value: &quot;256&quot;<br>        - name: NODE_NAME<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: spec.nodeName<br>        - name: CASSANDRA_DC<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: metadata.labels[&#39;cassandraclusters.db.orange.com.dc&#39;]<br>        - name: CASSANDRA_RACK<br>          valueFrom:<br>            fieldRef:<br>              apiVersion: v1<br>              fieldPath: metadata.labels[&#39;cassandraclusters.db.orange.com.rack&#39;]<br>        image: orangeopensource/cassandra-image:latest<br>        imagePullPolicy: Always<br>        lifecycle:<br>          preStop:<br>            exec:<br>              command:<br>              - /bin/bash<br>              - -c<br>              - /etc/cassandra/pre_stop.sh<br>        livenessProbe:<br>          exec:<br>            command:<br>            - /bin/bash<br>            - -c<br>            - nodetool status<br>          failureThreshold: 3<br>          initialDelaySeconds: 120<br>          periodSeconds: 10<br>          successThreshold: 1<br>          timeoutSeconds: 20<br>        name: cassandra<br>        ports:<br>        - containerPort: 7000<br>          name: intra-node<br>          protocol: TCP<br>        - containerPort: 7001<br>          name: intra-node-tls<br>          protocol: TCP<br>        - containerPort: 7199<br>          name: jmx-port<br>          protocol: TCP<br>        - containerPort: 9042<br>          name: cql<br>          protocol: TCP<br>        - containerPort: 1234<br>          name: promjmx<br>          protocol: TCP<br>        - containerPort: 8778<br>          name: jolokia<br>          protocol: TCP<br>        readinessProbe:<br>          exec:<br>            command:<br>            - /bin/bash<br>            - -c<br>            - /ready-probe.sh<br>          failureThreshold: 3<br>          initialDelaySeconds: 60<br>          periodSeconds: 10<br>          successThreshold: 1<br>          timeoutSeconds: 10<br>        resources:<br>          limits:<br>            cpu: &#39;1&#39;<br>            memory: 1Gi<br>          requests:<br>            cpu: &#39;1&#39;<br>            memory: 1Gi<br>        securityContext:<br>          capabilities:<br>            add:<br>            - IPC_LOCK<br>          procMount: Default<br>        terminationMessagePath: /dev/termination-log<br>        terminationMessagePolicy: File<br>      dnsPolicy: ClusterFirst<br>      restartPolicy: Always<br>      schedulerName: default-scheduler<br>      securityContext:<br>        fsGroup: 1<br>        runAsNonRoot: true<br>        runAsUser: 1000<br>      terminationGracePeriodSeconds: 1800<br>  updateStrategy:<br>    rollingUpdate:<br>      partition: 0<br>    type: RollingUpdate<br>status:<br>  collisionCount: 0<br>  currentReplicas: 3<br>  currentRevision: soft-anti-affinity-dc1-rack1-78d85d9586<br>  observedGeneration: 1<br>  readyReplicas: 3<br>  replicas: 3<br>  updateRevision: soft-anti-affinity-dc1-rack1-78d85d9586<br>  updatedReplicas: 3</pre><p>There is a lot here, but we just want to focus on the parts in bold, namely thespec.template.spec.affinity property:</p><pre><strong>template:</strong><br>    metadata:<br>      creationTimestamp: null<br>      <strong>labels:<br>        app: cassandracluster<br>        cassandracluster: soft-anti-affinity<br>        cassandraclusters.db.orange.com.dc: dc1<br>        cassandraclusters.db.orange.com.rack: rack1<br>        cluster: soft-anti-affinity<br>        dc-rack: dc1-rack1</strong><br>    spec:<br>      <strong>affinity:<br>        nodeAffinity: {}<br>        podAntiAffinity:<br>          preferredDuringSchedulingIgnoredDuringExecution:<br>          - podAffinityTerm:<br>              labelSelector:<br>                matchLabels:<br>                  app: cassandracluster<br>                  cassandracluster: soft-anti-affinity<br>                  cluster: soft-anti-affinity<br>              topologyKey: kubernetes.io/hostname</strong><br>            weight: 100</pre><p>For the soft-anti-affinity cluster, CassKop did not specify any affinity rules. This is evident from the fact that the nodeAffinity property is empty.</p><p>CassKop does however declare anti-affinity rules by setting the podAntiAffinity property. The preferredDuringSchedulingIgnoredDuringExecution rule says that a pod <em>should not</em> be scheduled on a node if is already running a pod that has labels that match the label selector. In other words, the Kubernetes scheduler should not schedule two Cassandra pods from soft-anti-affinity on the same node, but it will put them on the same node if there are insufficient resources to run them on separate nodes.</p><p>topologyKey essentially defines a topology domain. The matching, as specified by the label selectors, will apply to any node.</p><p>This type of scheduling rule can be convenient for development/testing scenarios in which it may be acceptable to run multiple Cassandra instances on the same Kubernetes nodes.</p><p>Note that while this anti-affinity rule results in the scheduler making a best effort to places pods from soft-anti-affinity onto separate nodes, it does not say anything about pods from other Cassandra clusters. For example, let’s say we create another CassandraCluster, another-cluster. The scheduler will happily place pods from soft-anti-affinity and another-cluster on the same node.</p><p>Let’s check the cluster status with nodetool:</p><pre>$ kubectl exec soft-anti-affinity-dc1-rack1-0 -- nodetool status -r | awk {&#39;print $1&quot; &quot;substr($2, 0, 30)&quot; &quot;$8&#39;} | column -t<br>Datacenter:      dc1<br>===============<br>Status=Up/Down<br>|/               State=Normal/Leaving/Joining/M<br>--               Address                         ID<br>UN               soft-anti-affinity-dc1-rack1-2  rack1<br>UN               soft-anti-affinity-dc1-rack1-0  rack1<br>UN               soft-anti-affinity-dc1-rack1-1  rack1</pre><p>There are a few things to note. First, the Cassandra cluster is healthy. All three Cassandra nodes are in the Up/Normal state.</p><p>Secondly, we are using a lot formatting used here. The motivation is to make the output more readable by focusing only on the most relevant parts.</p><p>Lastly, we use the -r flag withnodetool status in order to display the domain name which is also the pod name. This will help with determining on which Kubernetes node each Cassandra pod is running.</p><p>Now let’s query for pods:</p><pre>$ kubectl get pods -l cassandracluster=soft-anti-affinity -o wide | awk {&#39;print $1&quot; &quot;$7&#39;} | column -t<br>NAME                            NODE<br>soft-anti-affinity-dc1-rack1-0  gke-cass-dev-default-pool-daf646ab-<strong>j2m3</strong><br>soft-anti-affinity-dc1-rack1-1  gke-cass-dev-default-pool-daf646ab-<strong>5c6n</strong><br>soft-anti-affinity-dc1-rack1-2  gke-cass-dev-default-pool-daf646ab-<strong>sjbh</strong></pre><p>Each pod is running on a different node. If we add another instance to the soft-anti-affinity cluster, Kubernetes will schedule the pod on one of the nodes, as long as there are sufficient resources.</p><h3>Hard Anti-Affinity</h3><p>In this next example, we are going to make use of the hardAntiAffinity property of CassandraCluster for the first time:</p><pre># hard-anti-affinity.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: hard-anti-affinity<br>  labels:<br>    cluster: hard-anti-affinity<br>spec:<br>  nodesPerRacks: 3<br>  <strong>hardAntiAffinity: true</strong><br>  resources:<br>    requests:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi<br>    limits:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi</pre><p>hardAntiAffinity defaults to false. When set to true CassKop will generate a <em>must </em>or <em>hard</em> anti-affinity rule.</p><p>CassKop creates a StatefulSet named hard-anti-affinity-dc1-rack1. Let’s take a look at its spec.template.spec.affinity property:</p><pre>affinity:<br>  nodeAffinity: {}<br>    podAntiAffinity:<br>      <strong>requiredDuringSchedulingIgnoredDuringExecution</strong>:<br>      - labelSelector:<br>          matchLabels:<br>            app: cassandracluster<br>            cassandracluster: hard-anti-affinity<br>            cluster: hard-anti-affinity<br>        topologyKey: kubernetes.io/hostname</pre><p>This time we have a requireDuringSchedulingIgnoredDuringExecution rule which is a hard requirement. The scheduler will not run two pods from hard-anti-affinity on the same node.</p><p>Let’s check the cluster status with nodetool:</p><pre>$ kubectl exec hard-anti-affinity-dc1-rack1-0 -- nodetool status -r | awk {&#39;print $1&quot; &quot;substr($2, 0, 30)&quot; &quot;$8&#39;} | column -t<br>Datacenter:      dc1<br>===============<br>Status=Up/Down<br>|/               State=Normal/Leaving/Joining/M<br>--               Address                         ID<br>UN               hard-anti-affinity-dc1-rack1-2  rack1<br>UN               hard-anti-affinity-dc1-rack1-0  rack1<br>UN               hard-anti-affinity-dc1-rack1-1  rack1</pre><p>The Cassandra cluster looks healthy. All nodes are in the Up/Normal state. Now let’s query for pods:</p><pre>$ kubectl get pods -l cassandracluster=hard-anti-affinity -o wide | awk {&#39;print $1&quot; &quot;$7&#39;} | column -t<br>NAME                            NODE<br>hard-anti-affinity-dc1-rack1-0  gke-cass-dev-default-pool-daf646ab-<strong>j2m3</strong><br>hard-anti-affinity-dc1-rack1-1  gke-cass-dev-default-pool-daf646ab-<strong>5c6n</strong><br>hard-anti-affinity-dc1-rack1-2  gke-cass-dev-default-pool-daf646ab-<strong>sjbh</strong></pre><p>Each pod is running on a different node.</p><p>Let’s see what happens if we try to add a fourth Cassandra node. We can do this by changing the spec.nodesPerRack property in hard-anti-affinity.yaml to 4 and then run:</p><pre>$ kubectl apply -f hard-anti-affinity.yaml</pre><p>Check the status of the CassandraCluster:</p><pre>$ kubectl get cassandracluster hard-anti-affinity -o yaml<br>apiVersion: db.orange.com/v1alpha1<br>kind: CassandraCluster<br>...<br>status:<br>  cassandraRackStatus:<br>    dc1-rack1:<br>      cassandraLastAction:<br>        Name: ScaleUp<br>        startTime: &quot;2019-08-12T01:57:23Z&quot;<br>        status: Ongoing<br>      phase: Pending<br>      podLastOperation: {}<br><strong>  lastClusterAction: ScaleUp<br>  lastClusterActionStatus: Ongoing<br>  phase: Pending</strong><br>  seedlist:<br>  - hard-anti-affinity-dc1-rack1-0.hard-anti-affinity.default<br>  - hard-anti-affinity-dc1-rack1-1.hard-anti-affinity.default<br>  - hard-anti-affinity-dc1-rack1-2.hard-anti-affinity.default</pre><p>The status reports phase: Pending. The new pod has been created but not scheduled. Let’s take a look at the new pod:</p><pre>$ kubectl get pod hard-anti-affinity-dc1-rack1-3 -o yaml<br>apiVersion: v1<br>kind: Pod<br>...<br>status:<br>  conditions:<br>  - lastProbeTime: &quot;2019-08-12T02:15:45Z&quot;<br>    lastTransitionTime: &quot;2019-08-12T02:14:41Z&quot;<br>    <strong>message: &#39;0/3 nodes are available: 3 node(s) didn&#39;&#39;t match pod affinity/anti-affinity,<br>      3 node(s) didn&#39;&#39;t satisfy existing pods anti-affinity rules.&#39;<br>    reason: Unschedulable</strong><br>    status: &quot;False&quot;<br>    type: PodScheduled<br>  phase: Pending<br>  qosClass: Guaranteed</pre><p>The message tells us that no node satisfies the anti-affinity rule; therefore, the hard-anti-affinity-dc1-rack1-3 pod cannot run.</p><h3>Hard Affinity</h3><p>We are going to create a CassandraCluster that consists of a single data center with two racks. Each rack will be placed in a separate availability zone.</p><pre># hard-affinity.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: hard-affinity<br>  labels:<br>    cluster: hard-affinity<br>spec:<br>  nodesPerRacks: 3<br>  resources:<br>    requests:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi<br>    limits:<br>      cpu: &#39;1&#39;<br>      memory: 1Gi<br>  topology:<br>    dc:<br>      - name: dc1<br>        rack:<br>          - name: rack1<br>            <strong>labels:<br>              failure-domain.beta.kubernetes.io/zone: us-east1-b</strong><br>          - name: rack2<br>            <strong>labels:<br>              failure-domain.beta.kubernetes.io/zone: us-east1-c</strong></pre><p>This is the first time I have used the labels property of a rack. Any label can be specified; however, the label used here is not arbitrary.</p><p>Nodes in Kubernetes come pre-populated with a handful of labels, one of which is failure-domain.beta.kubernetes.io/zone. We are using the rack labels to tell CassKop to place rack1 in zone us-east1-b and rack2 in zone us-east1-c.</p><p>CassKop will create two StatefulSets for hard-affinity, one for each rack. Let’s take a look at the spec.template.spec.affinity property for one of the StatefulSets, hard-affinity-dc1-rack1:</p><pre>template:<br>    metadata:<br>      creationTimestamp: null<br>      labels:<br>        app: cassandracluster<br>        cassandracluster: hard-affinity<br>        cassandraclusters.db.orange.com.dc: dc1<br>        cassandraclusters.db.orange.com.rack: rack1<br>        cluster: hard-affinity<br>        dc-rack: dc1-rack1<br>    spec:<br>      affinity:<br>        <strong>nodeAffinity:<br>          requiredDuringSchedulingIgnoredDuringExecution:<br>            nodeSelectorTerms:<br>            - matchExpressions:<br>              - key: failure-domain.beta.kubernetes.io/zone<br>                operator: In<br>                values:<br>                - us-east1-b</strong><br>        podAntiAffinity:<br>          preferredDuringSchedulingIgnoredDuringExecution:<br>          - podAffinityTerm:<br>              labelSelector:<br>                matchLabels:<br>                  app: cassandracluster<br>                  cassandracluster: hard-affinity<br>                  cluster: hard-affinity<br>              topologyKey: kubernetes.io/hostname<br>            weight: 100</pre><p>CassKop has declared a requiredDuringSchedulingIgnoredDuringExecution rule which says that nodes <em>must </em>be scheduled in zone us-east1-b. We also have the anti-affinity rule that tells the scheduler to make a best effort to schedule pods on separate nodes.</p><p>CassKop creates a similar affinity rule for hard-affinity-dc1-rack2 but the value in the match expression is set to us-east1-c.</p><p>Let’s check the cluster status with nodetool:</p><pre>$ kubectl exec hard-affinity-dc1-rack2-0 -- nodetool status -r | awk {&#39;print $1&quot; &quot;substr($2, 0, 25)&quot; &quot;$8&#39;} | column -t<br>Datacenter:      dc1<br>===============<br>Status=Up/Down<br>|/               State=Normal/Leaving/Join<br>--               Address                    ID<br>UN               hard-affinity-dc1-rack2-1  rack2<br>UN               hard-affinity-dc1-rack1-2  rack1<br>UN               hard-affinity-dc1-rack2-0  rack2<br>UN               hard-affinity-dc1-rack1-1  rack1<br>UN               hard-affinity-dc1-rack2-2  rack2<br>UN               hard-affinity-dc1-rack1-0  rack1</pre><p>The Cassandra cluster looks healthy. All nodes are in the Up/Normal state. We have six Cassandra nodes spread across two racks.</p><p>The nodetool output does not provide enough information though to confirm that pods are running in the desired zones. Let’s inspect a bit more to verify that the pods are running where we expect them to be.</p><p>The Kubernetes cluster used for this example is made up of the following nodes:</p><pre>Node                                              | Zone<br>-------------------------------------------------------------<br>gke-cass-dev-multizone-default-pool-018f2d3d-0lbl | us-east1-d<br>gke-cass-dev-multizone-default-pool-018f2d3d-6lnk | us-east1-d<br>gke-cass-dev-multizone-default-pool-018f2d3d-7760 | us-east1-d<br>--------------------------------------------------|----------<br>gke-cass-dev-multizone-default-pool-112f0d40-564v | us-east1-c<br>gke-cass-dev-multizone-default-pool-112f0d40-db52 | us-east1-c<br>gke-cass-dev-multizone-default-pool-112f0d40-fdmg | us-east1-c<br>-------------------------------------------------------------<br>gke-cass-dev-multizone-default-pool-8060f7a0-j6sl | us-east1-b<br>gke-cass-dev-multizone-default-pool-8060f7a0-qgl2 | us-east1-b<br>gke-cass-dev-multizone-default-pool-8060f7a0-xm4t | us-east1-b</pre><p>Although this cluster has 3 nodes in us-east1-d, no Cassandra pods should be running in that zone.</p><p>Now let’s query for pods:</p><pre>$ kubectl get pods -l cassandracluster=hard-affinity -o wide | awk {&#39;print $1&quot; &quot;$7&#39;} | column -t<br>NAME                       NODE<br>hard-affinity-dc1-rack1-0  gke-cass-dev-multizone-default-pool-8060f7a0-j6sl<br>hard-affinity-dc1-rack1-1  gke-cass-dev-multizone-default-pool-8060f7a0-xm4t<br>hard-affinity-dc1-rack1-2  gke-cass-dev-multizone-default-pool-8060f7a0-qgl2<br>hard-affinity-dc1-rack2-0  gke-cass-dev-multizone-default-pool-112f0d40-db52<br>hard-affinity-dc1-rack2-1  gke-cass-dev-multizone-default-pool-112f0d40-fdmg<br>hard-affinity-dc1-rack2-2  gke-cass-dev-multizone-default-pool-112f0d40-564v</pre><p>The pods in rack1 are all running on nodes in zone us-east1-b, and the pods in rack2 are running on nodes in zone us-east1-c. All pods are running where we expect them to be running!</p><h3>Conclusion</h3><p>Different types of applications will have different performance profiles and different resource requirements. Cassandra boasts high performance, but that is largely dependent on available resources in terms of CPU, memory, and I/O. CassKop provides a flexible and intuitive way to make sure Cassandra runs on specific Kubernetes nodes. These scheduling capabilities are necessary components to be able to effectively run Cassandra in Kubernetes for production workloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b2f72d23293" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Cassandra in Kubernetes with Casskop]]></title>
            <link>https://itnext.io/deploying-cassandra-in-kubernetes-with-casskop-98956edfe32b?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/98956edfe32b</guid>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Sun, 04 Aug 2019 07:36:17 GMT</pubDate>
            <atom:updated>2019-08-04T07:36:17.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ea5ZtrKBydLA14RzW9GT7w.jpeg" /></figure><p><a href="https://github.com/Orange-OpenSource/cassandra-k8s-operator">CassKop</a> is a Kubernetes operator for Cassandra. It can create, configure, and manage Cassandra clusters running in Kubernetes. CassKop has a number of interesting features. One of those feature is data center- and rack-aware deployments, which is the focus of this post.</p><p>CassKop introduces a new Custom Resource Definition, CassandraCluster, which allows you to specify a number things like:</p><ul><li>The CPU and memory resources</li><li><a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity">Node anti-affinity</a></li><li>Resource limits</li><li>Storage class</li><li>Topology (in terms of data center and rack configuration)</li></ul><p>This post explores how to configure some different Cassandra cluster topologies.</p><h3>Install CassKop</h3><p>CassKop is available is as <a href="https://helm.sh/">Helm</a> chart. Helm is the easiest way to deploy the operator. Setting up Helm is outside the scope of this post; so, I will simply refer you to the <a href="https://helm.sh/docs/using_helm/#installing-helm">user guide</a> for details on its installation. Be sure to also review <a href="https://helm.sh/docs/using_helm/#role-based-access-control">setting up RBAC for Tiller</a> as well.</p><p>The latest Helm chart for the operator can be found in the CassKop repository on GitHub. The first thing to do is add the repository:</p><pre>$ helm repo add casskop <a href="https://orange-opensource.github.io/cassandra-k8s-operator/helm">https://Orange-OpenSource.github.io/cassandra-k8s-operator/helm</a></pre><p>Then deploy CassKop:</p><pre>$ helm install --name casskop casskop/cassandra-operator<br>NAME:   casskop<br>LAST DEPLOYED: Tue Jul 30 21:13:51 2019<br>NAMESPACE: default<br>STATUS: DEPLOYEDRESOURCES:<br>==&gt; v1/Deployment<br>NAME                        READY  UP-TO-DATE  AVAILABLE  AGE<br>casskop-cassandra-operator  0/1    1           0          1s==&gt; v1/Pod(related)<br>NAME                                         READY  STATUS             RESTARTS  AGE<br>casskop-cassandra-operator-79f77bb4c8-b4mf7  0/1    ContainerCreating  0         1s==&gt; v1/RoleBinding<br>NAME                AGE<br>cassandra-operator  1s==&gt; v1/ServiceAccount<br>NAME                SECRETS  AGE<br>cassandra-operator  1        1s==&gt; v1beta1/Role<br>NAME                AGE<br>cassandra-operator  1sNOTES:<br>Congratulations. You have just deployed CassKop the Cassandra Operator.<br>Check its status by running:<br>kubectl --namespace default get pods -l &quot;release=casskop&quot;Visit <a href="https://github.com/Orange-OpenSource/cassandra-k8s-operator">https://github.com/Orange-OpenSource/cassandra-k8s-operator</a> for instructions on hot to create &amp; configure Cassandra clusters using the operator.</pre><p>Before proceeding, make sure that the operator has deployed successfully:</p><pre>$ kubectl get pods -l name=cassandra-operator<br>NAME                                          READY   STATUS    RESTARTS   AGE<br>casskop-cassandra-operator-79f77bb4c8-b4mf7   1/1     Running   0          108s</pre><h3>Deploy Simple Cluster</h3><p>We start off with a minimal CassandraClusterthat does not define any data centers or racks.</p><pre># simple-cluster.yamlapiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: simple-cluster<br>  labels:<br>    cluster: simple-cluster<br>spec:<br>  <strong>nodesPerRacks: 3</strong><br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi</pre><p>Because neither data centers nor racks are defined, nodesPerRacksin effect specifies the cluster size.</p><p>Create the cluster with:</p><pre>$ kubectl apply -f simple-cluster.yaml</pre><p>Eventually we should see three pods that make up the Cassandra cluster. Let’s query for the pods:</p><pre>$ kubectl get pods  -l cassandracluster=simple-cluster<br>NAME                         READY   STATUS    RESTARTS   AGE<br>simple-cluster-dc1-rack1-0   1/1     Running   0          12h<br>simple-cluster-dc1-rack1-1   1/1     Running   0          12h<br>simple-cluster-dc1-rack1-2   1/1     Running   0          12h</pre><p><strong>Note:</strong> CassKop adds the cassandraclusterlabel.</p><p>CassKop does not directly create the pods. The pods are managed by a StatefulSet which CassKop creates.</p><pre>$ kubectl get statefulset -l cassandracluster=simple-cluster<br>NAME                       DESIRED   CURRENT   AGE<br>simple-cluster-dc1-rack1    3         3        12h</pre><p>StatefulSets require use of a headless service to be responsible for network identify of the pods. Let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=simple-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>simple-cluster               ClusterIP  None        &lt;none&gt;<br>simple-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>We have our headless service simple-cluster. The other service, simple-cluster-exporter-jmx, is for exposing metrics to Prometheus.</p><p>Now let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec simple-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.18  69.94 KiB  256          69.0%             rack1<br>UN  10.0.5.6   87.38 KiB  256          65.0%             rack1<br>UN  10.0.3.7   104.86 KiB  256         65.9%             rack1</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>All three Cassandra nodes are in the Up/Normal state. The Cassandra cluster is fully operational at this point. With a minimal spec, we are able to get a cluster up and running.</p><h3>The Snitch</h3><p>I want to talk briefly about the snitch which is configured in cassandra.yamlwith the endpoint_snitch property. The Cassandra out of box default is SimpleSnitch. CassKop configures Cassandra nodes to use GossipingPropertyFileSnitch.</p><h3>Multiple Racks</h3><p>Next we will look at a slightly more involved example that involves multiple racks:</p><pre># racks-cluster.yamlapiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: racks-cluster<br>spec:<br>  nodesPerRacks: 2<br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi<br>  <strong>topology:<br>    dc:<br>      - name: dc1</strong><br>        <strong>rack:<br>          - name: rack1<br>          - name: rack2<br>          - name: rack3</strong></pre><p>Here we see the topology property for the first time. It declares a single data center and three racks. topology accepts a list of data centers. Each data center accepts a list of racks. This spec should produce a Cassandra cluster with 6 nodes spread across three racks.</p><p>Let’s query for the pods:</p><pre>$ kubectl get pods -l cassandracluster=racks-cluster<br>NAME                        READY   STATUS    RESTARTS   AGE<br>racks-cluster-dc1-rack1-0   1/1     Running   0          18m<br>racks-cluster-dc1-rack1-1   1/1     Running   0          17m<br>racks-cluster-dc1-rack2-0   1/1     Running   0          15m<br>racks-cluster-dc1-rack2-1   1/1     Running   0          14m<br>racks-cluster-dc1-rack3-0   1/1     Running   0          13m<br>racks-cluster-dc1-rack3-1   1/1     Running   0          11m</pre><p>We have six pods as expected. I previously mentioned that CassKop creates a StatefulSet which manages the pods. Let’s query for the StatefulSet:</p><pre>$ kubectl get statefulset -l cassandracluster=racks-cluster<br>NAME                      DESIRED   CURRENT   AGE<br>racks-cluster-dc1-rack1   2         2         21m<br>racks-cluster-dc1-rack2   2         2         18m<br>racks-cluster-dc1-rack3   2         2         15m</pre><p>This time we have three StatefulSets. CassKop creates a StatefulSet per rack.</p><p>Let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=racks-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>racks-cluster               ClusterIP  None        &lt;none&gt;<br>racks-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>It is possible to use the same headless service for multiple StatefuleSets. That is exactly what CassKop does.</p><p>Now let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec racks-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.19  87.34 KiB  256          30.5%             rack2<br>UN  10.0.4.5   92.34 KiB  256          32.8%             rack1<br>UN  10.0.0.6   81.63 KiB  256          31.9%             rack3<br>UN  10.0.5.7   69.94 KiB  256          36.0%             rack1<br>UN  10.0.3.8   87.38 KiB  256          33.9%             rack2<br>UN  10.0.1.8   69.92 KiB  256          35.0%             rack3</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>All six Cassandra nodes are in the Up/Normal state and spread across three racks as expected.</p><h3>Multiple Data Centers</h3><p>Lastly, we will look at a multi-DC deployment.</p><pre># multidc-cluster.yamlapiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: multidc-cluster<br>spec:<br>  nodesPerRacks: 2<br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi<br>  topology:<br>    <strong>dc:<br>      - name: dc1<br>        rack:<br>          - name: rack1<br>          - name: rack2<br>          - name: rack3<br>      - name: dc2<br>        nodesPerRacks: 3<br>        rack:<br>          - name: rack1<br>          - name: rack2</strong></pre><p>Notice that in addition to declaring data centers dc1 and dc2 we also have set nodesPerRacks for dc2. CassKop enforces the number of nodes per rack to be the same within a data center. The number of nodes per rack can vary across data centers. The number of racks per data center can also vary. This provides a lot flexibility for configuring the cluster topology.</p><p>This spec should produce a Cassandra cluster with twelve Cassandra nodes. Let’s query for the pods:</p><pre>$ kubectl get pods -l cassandracluster=multidc-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&#39;} | column -t<br>NAME                         READY  STATUS<br>multidc-cluster-dc1-rack1-0  1/1    Running<br>multidc-cluster-dc1-rack1-1  1/1    Running<br>multidc-cluster-dc1-rack2-0  1/1    Running<br>multidc-cluster-dc1-rack2-1  1/1    Running<br>multidc-cluster-dc1-rack3-0  1/1    Running<br>multidc-cluster-dc1-rack3-1  1/1    Running<br>multidc-cluster-dc2-rack1-0  1/1    Running<br>multidc-cluster-dc2-rack1-1  1/1    Running<br>multidc-cluster-dc2-rack1-2  1/1    Running<br>multidc-cluster-dc2-rack2-0  1/1    Running<br>multidc-cluster-dc2-rack2-1  1/1    Running<br>multidc-cluster-dc2-rack2-2  1/1    Running</pre><p>We have 12 pods as expected. Let’s query for the StatefulSets:</p><pre>$ kubectl get statefulset -l cassandracluster=multidc-cluster<br>NAME                        DESIRED   CURRENT   AGE<br>multidc-cluster-dc1-rack1   2         2         8h<br>multidc-cluster-dc1-rack2   2         2         8h<br>multidc-cluster-dc1-rack3   2         2         7h58m<br>multidc-cluster-dc2-rack1   3         3         7h55m<br>multidc-cluster-dc2-rack2   3         3         7h51m</pre><p>As expected we have five StatefulSets, one per rack.</p><p>Now let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=multidc-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>multidc-cluster               ClusterIP  None        &lt;none&gt;<br>multidc-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>Hopefully it is clear now that CassKop only creates one set of headless services, regardless of the number of data centers and racks.</p><p>Lastly, let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec multidc-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.2   200.27 KiB  256          14.3%            rack2<br>UN  10.0.4.6   299.47 KiB  256          14.4%            rack2<br>UN  10.0.0.7   314.06 KiB  256          15.5%            rack3<br>UN  10.0.5.9   294.07 KiB  256          15.0%            rack1<br>UN  10.0.1.9   270.8 KiB   256          16.3%            rack3<br>UN  10.0.3.10  289.84 KiB  256          15.6%            rack1<br>Datacenter: dc2<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.22  327.84 KiB  256          15.9%            rack1<br>UN  10.0.4.7   233.92 KiB  256          14.9%            rack2<br>UN  10.0.0.8   254.63 KiB  256          14.8%            rack2<br>UN  10.0.5.10  243.91 KiB  256          15.7%            rack1<br>UN  10.0.1.10  254.97 KiB  256          15.5%            rack2<br>UN  10.0.3.11  309.45 KiB  256          15.9%            rack1</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>We have twelve Cassandra nodes spread across two data centers. dc1 has six nodes spread across three racks. dc2 has six nodes spread across two racks. Everything checks out!</p><h3>Conclusion</h3><p>CassKop offers a lot of flexibility in configuring the topology of Cassandra clusters running in Kubernetes. Data centers are a central feature of Cassandra, and CassKop fully exploit the feature by making every cluster that it create data center-aware.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98956edfe32b" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/deploying-cassandra-in-kubernetes-with-casskop-98956edfe32b">Deploying Cassandra in Kubernetes with Casskop</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Cassandra in Kubernetes with Casskop]]></title>
            <link>https://john-sanda.medium.com/deploying-cassandra-in-kubernetes-with-casskop-1f721586825b?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f721586825b</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cassandra]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Thu, 01 Aug 2019 04:59:19 GMT</pubDate>
            <atom:updated>2019-08-01T04:59:19.697Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/Orange-OpenSource/cassandra-k8s-operator">CassKop</a> is a Kubernetes operator for Cassandra. It can create, configure, and manage Cassandra clusters running in Kubernetes. CassKop has a number of interesting features. One of those feature is data center- and rack-aware deployments, which is the focus of this post.</p><p>CassKop introduces a new Custom Resource Definition, CassandraCluster, which allows you to specify a number things like:</p><ul><li>The CPU and memory resources</li><li><a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity">Node anti-affinity</a></li><li>Resource limits</li><li>Storage class</li><li>Topology (in terms of data center and rack configuration)</li></ul><p>This post explores how to configure some different Cassandra cluster topologies.</p><h3>Install CassKop</h3><p>CassKop is available is as <a href="https://helm.sh/">Helm</a> chart. Helm is the easiest way to deploy the operator. Setting up Helm is outside the scope of this post; so, I will simply refer you to the <a href="https://helm.sh/docs/using_helm/#installing-helm">user guide</a> for details on its installation. Be sure to also review <a href="https://helm.sh/docs/using_helm/#role-based-access-control">setting up RBAC for Tiller</a> as well.</p><p>The latest Helm chart for the operator can be found in the CassKop repository on GitHub. The first thing to do is add the repository:</p><pre>$ helm repo add casskop <a href="https://orange-opensource.github.io/cassandra-k8s-operator/helm">https://Orange-OpenSource.github.io/cassandra-k8s-operator/helm</a></pre><p>Then deploy CassKop:</p><pre>$ helm install --name casskop casskop/cassandra-operator<br>NAME:   casskop<br>LAST DEPLOYED: Tue Jul 30 21:13:51 2019<br>NAMESPACE: default<br>STATUS: DEPLOYED</pre><pre>RESOURCES:<br>==&gt; v1/Deployment<br>NAME                        READY  UP-TO-DATE  AVAILABLE  AGE<br>casskop-cassandra-operator  0/1    1           0          1s</pre><pre>==&gt; v1/Pod(related)<br>NAME                                         READY  STATUS             RESTARTS  AGE<br>casskop-cassandra-operator-79f77bb4c8-b4mf7  0/1    ContainerCreating  0         1s</pre><pre>==&gt; v1/RoleBinding<br>NAME                AGE<br>cassandra-operator  1s</pre><pre>==&gt; v1/ServiceAccount<br>NAME                SECRETS  AGE<br>cassandra-operator  1        1s</pre><pre>==&gt; v1beta1/Role<br>NAME                AGE<br>cassandra-operator  1s</pre><pre>NOTES:<br>Congratulations. You have just deployed CassKop the Cassandra Operator.<br>Check its status by running:<br>kubectl --namespace default get pods -l &quot;release=casskop&quot;</pre><pre>Visit <a href="https://github.com/Orange-OpenSource/cassandra-k8s-operator">https://github.com/Orange-OpenSource/cassandra-k8s-operator</a> for instructions on hot to create &amp; configure Cassandra clusters using the operator.</pre><p>Before proceeding, make sure that the operator has deployed successfully:</p><pre>$ kubectl get pods -l name=cassandra-operator<br>NAME                                          READY   STATUS    RESTARTS   AGE<br>casskop-cassandra-operator-79f77bb4c8-b4mf7   1/1     Running   0          108s</pre><h3>Deploy Simple Cluster</h3><p>We start off with a minimal CassandraClusterthat does not define any data centers or racks.</p><pre># simple-cluster.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: simple-cluster<br>  labels:<br>    cluster: simple-cluster<br>spec:<br>  <strong>nodesPerRacks: 3</strong><br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi</pre><p>Because neither data centers nor racks are defined, nodesPerRacksin effect specifies the cluster size.</p><p>Create the cluster with:</p><pre>$ kubectl apply -f simple-cluster.yaml</pre><p>Eventually we should see three pods that make up the Cassandra cluster. Let’s query for the pods:</p><pre>$ kubectl get pods  -l cassandracluster=simple-cluster<br>NAME                         READY   STATUS    RESTARTS   AGE<br>simple-cluster-dc1-rack1-0   1/1     Running   0          12h<br>simple-cluster-dc1-rack1-1   1/1     Running   0          12h<br>simple-cluster-dc1-rack1-2   1/1     Running   0          12h</pre><p><strong>Note:</strong> CassKop adds the cassandraclusterlabel.</p><p>CassKop does not directly create the pods. The pods are managed by a StatefulSet which CassKop creates.</p><pre>$ kubectl get statefulset -l cassandracluster=simple-cluster<br>NAME                       DESIRED   CURRENT   AGE<br>simple-cluster-dc1-rack1    3         3        12h</pre><p>StatefulSets require use of a headless service to be responsible for network identify of the pods. Let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=simple-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>simple-cluster               ClusterIP  None        &lt;none&gt;<br>simple-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>We have our headless service simple-cluster. The other service, simple-cluster-exporter-jmx, is for exposing metrics to Prometheus.</p><p>Now let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec simple-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.18  69.94 KiB  256          69.0%             rack1<br>UN  10.0.5.6   87.38 KiB  256          65.0%             rack1<br>UN  10.0.3.7   104.86 KiB  256         65.9%             rack1</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>All three Cassandra nodes are in the Up/Normal state. The Cassandra cluster is fully operational at this point. With a minimal spec, we are able to get a cluster up and running.</p><h3>The Snitch</h3><p>I want to talk briefly about the snitch which is configured in cassandra.yaml with the endpoint_snitch property. The Cassandra out of box default is SimpleSnitch. CassKop configures Cassandra nodes to use GossipingPropertyFileSnitch.</p><h3>Multiple Racks</h3><p>Next we will look at a slightly more involved example that involves multiple racks:</p><pre># racks-cluster.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: racks-cluster<br>spec:<br>  nodesPerRacks: 2<br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi<br>  <strong>topology:<br>    dc:<br>      - name: dc1</strong><br>        <strong>rack:<br>          - name: rack1<br>          - name: rack2<br>          - name: rack3</strong></pre><p>Here we see the topology property for the first time. It declares a single data center and three racks. topology accepts a list of data centers. Each data center accepts a list of racks. This spec should produce a Cassandra cluster with 6 nodes spread across three racks.</p><p>Let’s query for the pods:</p><pre>$ kubectl get pods -l cassandracluster=racks-cluster<br>NAME                        READY   STATUS    RESTARTS   AGE<br>racks-cluster-dc1-rack1-0   1/1     Running   0          18m<br>racks-cluster-dc1-rack1-1   1/1     Running   0          17m<br>racks-cluster-dc1-rack2-0   1/1     Running   0          15m<br>racks-cluster-dc1-rack2-1   1/1     Running   0          14m<br>racks-cluster-dc1-rack3-0   1/1     Running   0          13m<br>racks-cluster-dc1-rack3-1   1/1     Running   0          11m</pre><p>We have six pods as expected. I previously mentioned that CassKop creates a StatefulSet which manages the pods. Let’s query for the StatefulSet:</p><pre>$ kubectl get statefulset -l cassandracluster=racks-cluster<br>NAME                      DESIRED   CURRENT   AGE<br>racks-cluster-dc1-rack1   2         2         21m<br>racks-cluster-dc1-rack2   2         2         18m<br>racks-cluster-dc1-rack3   2         2         15m</pre><p>This time we have three StatefulSets. CassKop creates a StatefulSet per rack.</p><p>Let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=racks-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>racks-cluster               ClusterIP  None        &lt;none&gt;<br>racks-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>It is possible to use the same headless service for multiple StatefuleSets. That is exactly what CassKop does.</p><p>Now let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec racks-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.19  87.34 KiB  256          30.5%             rack2<br>UN  10.0.4.5   92.34 KiB  256          32.8%             rack1<br>UN  10.0.0.6   81.63 KiB  256          31.9%             rack3<br>UN  10.0.5.7   69.94 KiB  256          36.0%             rack1<br>UN  10.0.3.8   87.38 KiB  256          33.9%             rack2<br>UN  10.0.1.8   69.92 KiB  256          35.0%             rack3</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>All six Cassandra nodes are in the Up/Normal state and spread across three racks as expected.</p><h3>Multiple Data Centers</h3><p>Lastly, we will look at a multi-DC deployment.</p><pre># multidc-cluster.yaml</pre><pre>apiVersion: &quot;db.orange.com/v1alpha1&quot;<br>kind: &quot;CassandraCluster&quot;<br>metadata:<br>  name: multidc-cluster<br>spec:<br>  nodesPerRacks: 2<br>  resources:<br>    requests:<br>      cpu: 400m<br>      memory: 1Gi<br>    limits:<br>      cpu: 400m<br>      memory: 1Gi<br>  topology:<br>    <strong>dc:<br>      - name: dc1<br>        rack:<br>          - name: rack1<br>          - name: rack2<br>          - name: rack3<br>      - name: dc2<br>        nodesPerRacks: 3<br>        rack:<br>          - name: rack1<br>          - name: rack2</strong></pre><p>Notice that in addition to declaring data centers dc1 and dc2 we also have set nodesPerRacks for dc2. CassKop enforces the number of nodes per rack to be the same within a data center. The number of nodes per rack can vary across data centers. The number of racks per data center can also vary. This provides a lot flexibility for configuring the cluster topology.</p><p>This spec should produce a Cassandra cluster with twelve Cassandra nodes. Let’s query for the pods:</p><pre>$ kubectl get pods -l cassandracluster=multidc-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&#39;} | column -t<br>NAME                         READY  STATUS<br>multidc-cluster-dc1-rack1-0  1/1    Running<br>multidc-cluster-dc1-rack1-1  1/1    Running<br>multidc-cluster-dc1-rack2-0  1/1    Running<br>multidc-cluster-dc1-rack2-1  1/1    Running<br>multidc-cluster-dc1-rack3-0  1/1    Running<br>multidc-cluster-dc1-rack3-1  1/1    Running<br>multidc-cluster-dc2-rack1-0  1/1    Running<br>multidc-cluster-dc2-rack1-1  1/1    Running<br>multidc-cluster-dc2-rack1-2  1/1    Running<br>multidc-cluster-dc2-rack2-0  1/1    Running<br>multidc-cluster-dc2-rack2-1  1/1    Running<br>multidc-cluster-dc2-rack2-2  1/1    Running</pre><p>We have 12 pods as expected. Let’s query for the StatefulSets:</p><pre>$ kubectl get statefulset -l cassandracluster=multidc-cluster<br>NAME                        DESIRED   CURRENT   AGE<br>multidc-cluster-dc1-rack1   2         2         8h<br>multidc-cluster-dc1-rack2   2         2         8h<br>multidc-cluster-dc1-rack3   2         2         7h58m<br>multidc-cluster-dc2-rack1   3         3         7h55m<br>multidc-cluster-dc2-rack2   3         3         7h51m</pre><p>As expected we have five StatefulSets, one per rack.</p><p>Now let’s query for the headless service:</p><pre>$ kubectl get svc -l cassandracluster=multidc-cluster | awk {&#39;print $1&quot; &quot; $2&quot; &quot;$3&quot; &quot;$4&#39;} | column -t<br>NAME                          TYPE       CLUSTER-IP  EXTERNAL-IP<br>multidc-cluster               ClusterIP  None        &lt;none&gt;<br>multidc-cluster-exporter-jmx  ClusterIP  None        &lt;none&gt;</pre><p>Hopefully it is clear now that CassKop only creates one set of headless services, regardless of the number of data centers and racks.</p><p>Lastly, let’s check the Cassandra cluster status with nodetool:</p><pre>$ kubectl exec multidc-cluster-dc1-rack1-0 -- nodetool status<br>Datacenter: dc1<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.2   200.27 KiB  256          14.3%            rack2<br>UN  10.0.4.6   299.47 KiB  256          14.4%            rack2<br>UN  10.0.0.7   314.06 KiB  256          15.5%            rack3<br>UN  10.0.5.9   294.07 KiB  256          15.0%            rack1<br>UN  10.0.1.9   270.8 KiB   256          16.3%            rack3<br>UN  10.0.3.10  289.84 KiB  256          15.6%            rack1<br>Datacenter: dc2<br>===============<br>Status=Up/Down<br>|/ State=Normal/Leaving/Joining/Moving<br>--  Address    Load       Tokens       Owns (effective)  Rack<br>UN  10.0.2.22  327.84 KiB  256          15.9%            rack1<br>UN  10.0.4.7   233.92 KiB  256          14.9%            rack2<br>UN  10.0.0.8   254.63 KiB  256          14.8%            rack2<br>UN  10.0.5.10  243.91 KiB  256          15.7%            rack1<br>UN  10.0.1.10  254.97 KiB  256          15.5%            rack2<br>UN  10.0.3.11  309.45 KiB  256          15.9%            rack1</pre><p><strong>Note: </strong>The Host ID column has been removed from the output to improve readability.</p><p>We have twelve Cassandra nodes spread across two data centers. dc1 has six nodes spread across three racks. dc2 has six nodes spread across two racks. Everything checks out!</p><h3>Conclusion</h3><p>CassKop offers a lot of flexibility in configuring the topology of Cassandra clusters running in Kubernetes. Data centers are a central feature of Cassandra, and CassKop fully exploit the feature by making every cluster that it create data center-aware.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f721586825b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running tlp-stress in Kubernetes]]></title>
            <link>https://john-sanda.medium.com/running-tlp-stress-in-kubernetes-3b6e77337533?source=rss-683e7d1684dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b6e77337533</guid>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[John Sanda]]></dc:creator>
            <pubDate>Tue, 16 Jul 2019 17:00:55 GMT</pubDate>
            <atom:updated>2019-07-16T17:05:26.210Z</atom:updated>
            <content:encoded><![CDATA[<p>Running Cassandra in Kubernetes presents some interesting challenges. Performance is almost always an important consideration with Cassandra, no less so when running in Kubernetes. In this post, I demonstrate how to deploy <a href="https://github.com/thelastpickle/tlp-stress">tlp-stress</a> in Kubernetes and run it against a Cassandra cluster that is also running in the same Kubernetes cluster.</p><p>tlp-stress is a workload-centric tool for stress testing and benchmarking Cassandra. It is developed and maintained by my colleagues at The Last Pickle. If you are not familiar with it, checkout this <a href="https://thelastpickle.com/blog/2018/10/31/tlp-stress-intro.html">introductory article</a> along with <a href="https://thelastpickle.com/blog/2019/07/09/tlp-stress-update.html">this one</a> for a great overview.</p><p>Enough with formalities. Let’s get to the good stuff!</p><h3>Create the Image</h3><p>In order to run tlp-stress in Kubernetes we need a Docker image. The project does not (yet) publish Docker images, but it easy to create one.</p><p>First, I need to clone the git repo:</p><pre>$ git clone <a href="https://github.com/thelastpickle/tlp-stress.git">https://github.com/thelastpickle/tlp-stress.git</a></pre><p>Take a look at build.gradle. Around line 12 you should see a plugins section that looks like:</p><pre>plugins {<br>    id &#39;com.google.cloud.tools.jib&#39; version &#39;0.9.11&#39;<br>}</pre><p><a href="https://github.com/GoogleContainerTools/jib">jib</a> is a project that builds optimized Docker images for Maven and Gradle projects. It builds the image without using Docker which means you do not need the Docker daemon running locally. Pretty cool. The images are optimized in that they use <a href="https://github.com/GoogleContainerTools/distroless">distroless</a> base images. Distroless images are minimal images that contain only the application and its runtime dependencies. This results in very small image sizes.</p><p>In my local branch I have update the jib plugin to the latest version, which is 1.3.0 at the time of this writing.</p><p>To create and push the image to docker hub I run:</p><pre># If you are following the steps be sure to replace jsanda with your docker hub username</pre><pre>$ ./gradlew jib --image=jsanda/tlp-stress:demo</pre><p>You will find the image on docker hub <a href="https://cloud.docker.com/repository/docker/jsanda/tlp-stress/tags">here</a>.</p><h3>Deploy Cassandra</h3><p>We need a Cassandra cluster running before we can successfully deploy tlp-stress. I am not going to cover how to deploy Cassandra in Kubernetes in this article. If you are not familiar with deploying Cassandra in Kubernetes check out <a href="https://kubernetes.io/docs/tutorials/stateful-application/cassandra/">Deploying Cassandra with Stateful Sets</a>. In some future posts however, I will explore more robust deployment options.</p><p>For now, let’s take a look at small cluster that I have running in GKE:</p><pre>$ kubectl get statefulset<br>NAME                       READY   AGE<br>cassandra-demo-dc1-rack1   2/2     4m21s</pre><pre>$ kubectl get svc<br>NAME                          TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                               AGE<br>cassandra-demo                ClusterIP   None         &lt;none&gt;        7000/TCP,7001/TCP,7199/TCP,9042/TCP   5m45s</pre><p>The stateful set that manages the two pods in which Cassandra runs. The headless service allows clients, like tlp-stress, to connect to the Cassandra cluster.</p><h3>Create a Job</h3><p>tlp-stress is not designed to run indefinitely. It terminates when it finishes. It is therefore better suited to run as a Job than as a Deployment.</p><p>Here is the job spec:</p><pre>apiVersion: batch/v1<br>kind: Job<br>metadata:<br>  name: tlp-stress<br>spec:<br>  template:<br>    spec:<br>      restartPolicy: OnFailure<br>      containers:<br>      - name: tlp-stress<br>        image: jsanda/tlp-stress:demo<br>        imagePullPolicy: IfNotPresent<br>        args: [&quot;run&quot;, &quot;KeyValue&quot;, &quot;--host&quot;, &quot;cassandra-demo&quot;, &quot;--duration&quot;, &quot;30m&quot;]</pre><p>Next, deploy the job:</p><pre>$ kubectl apply -f tlp-stress-job.yaml</pre><p>Check that the job is running:</p><pre>$ kubectl get jobs<br>NAME         COMPLETIONS   DURATION   AGE<br>tlp-stress   0/1           92s        92s</pre><pre>$ kubectl get pods -l job-name=tlp-stress<br>NAME               READY   STATUS    RESTARTS   AGE<br>tlp-stress-hwd69   1/1     Running   0          2m57s</pre><p>Here is a screenshot of the pod logs that verify tlp-stress is running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*x5jdxvSfPCnxFOkgfneuIg.png" /></figure><h3>Conclusion</h3><p>This post demonstrates how to quickly and easily get tlp-stress running in Kubernetes. This is a just PoC to show how things work. In future posts, I will report on testing some real-world cluster configurations. It will be interesting to see how Cassandra performance compares when running inside versus outside of Kubernetes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b6e77337533" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>