Skip to content

Slack Notification#

  • This feature will be supported from v0.8.0 onwards.
  • Kubesaver can be configured to notify the resources defined in rules when they are scaled down and scaled up
  • Every rule in rules can be configured to alert to unique slack channel. This gives the flexibilty to notify the owners of the resources.

Configuring slack app and token#

  • Create slack app and configure the Workspace. Follow the guidelines: https://api.slack.com/apps
  • In Add features and functionality, Select Permissions and set the Scopes by clicking Add an OAuth Scope
  • Select Bot User OAuth Token
  • Select chat:write permission to write chat to workspace and files:write for uploading the files.
  • Copy the token(xoxb-....) which will be uploaded as a Kubernetes secret in the Cluster.

Kubernetes manifest#

  • Mount the slack token as a file in the path /var/slack_token reference: Secret as file
    Or
  • Set slack token as a Environment Variable SLACK_API_TOKEN using Kubernetes secret: Secret as evn

  • Store the secret in Google GSM or AWS Secret Manager and use Kubernetes Secrets CSI Driver to get the secret and mount the secret as a volume to the Deployment manifest

Configurations & Installation#

  1. Create Slack Token Secret
echo -n 'xoxb-xxx' > ./slack.txt
kubectl create secret generic slack-token --from-file=./slack.txt --namespace kube-saver
  1. Update rules.yaml
rules:
  - id: rules-downscale-kuber1
    uptime: Mon-Sun 22:59-23:00 Australia/Sydney
    jmespath: "metadata.name == 'kuber1'"
    resource:
      - Namespace
    slack_channel: C040RXXXXXX
    replicas: 0
  - id: rules-downscale-kuber2
    uptime: Mon-Sun 00:00-23:59 Australia/Sydney # all up
    jmespath: "metadata.name == 'kuber2'"
    resource:
      - Namespace
    replicas: 0
    slack_channel: C040RYYYYYY
  1. Update the deployment manifest in k8s/install.yaml
# slack token as a file
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: kube-saver
  name: kube-saver-operator
  labels:
    app: kube-saver-operator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kube-saver-operator
  template:
    metadata:
      labels:
        app: kube-saver-operator
    spec:
      serviceAccountName: kube-saver
      containers:
        - name: kube-saver-operator
          image: maheshrayas/kube-saver:v0.8.0
          args:
            - "--rules=/config/rules.yaml" #rules for downscale
            - "--interval=60" # every 60 secs, the controller will check the resources to downscale or upscale
            - "--debug" # remove to set log as INFO
            - "--comm-type=slack" # notification type is slack, pass this arg if you want notified to slack
            - "--comm-details=<slackworkspace>" # slack workspace name, pass this arg if comm-type is set to slack
          resources:
            limits:
              cpu: "1"
              memory: 500Mi
            requests:
              cpu: "0.5"
              memory: 100Mi
          imagePullPolicy: Always
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
            readOnlyRootFilesystem: false # Create tmp file for slack notification
            runAsGroup: 1001
            runAsNonRoot: true
            runAsUser: 1001
            seccompProfile:
              type: RuntimeDefault
          volumeMounts:
            - name: config-volume
              mountPath: /config
            - name: slack-api-token
              mountPath: "/var/slack_token"
              readOnly: true
            - mountPath: /tmp
              name: tmp-volume
      volumes:
        - name: tmp-volume
          emptyDir: {}
        - name: config-volume
          configMap:
            name: rules
        - name: slack-api-token
          secret:
            secretName: slack-token
            optional: false # default setting; "slack-token" must exist
  1. Install
  kubectl apply -k k8s/