How cool it is to run the kubectl
commands from slack channel… 🙂
This is not fully developed yet, but it comes in handy with dev, staging ENV.
Let’s Begin.
Requirements:
1. create a new slack bot
2. Create Slack Channel(not private), and get the channel ID.
https://slack.com/api/channels.list?token=REPLACE_TOKEN&pretty=1 to get the Channel ID here.
3. Add Slack-bot to the channel you created.
4. Then use the below file to create K8s Deployment.
---
#create servuce account
apiVersion: v1
kind: ServiceAccount
metadata:
name: kubebot-user
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubebot-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
# Create ClusterRole with Ref NOTE : clsuter-admin is more powerful
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubebot-user
namespace: default
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kubebot
labels:
component: kubebot
spec:
replicas: 1
template:
metadata:
labels:
component: kubebot
spec:
serviceAccountName: kubebot-user
containers:
- name: kubebot
image: harbur/kubebot:0.1.0
imagePullPolicy: Always
env:
# Create a secret with your slack bot token and reference it here
- name: KUBEBOT_SLACK_TOKEN
value: TOKENID_THAT_WAS CREATED
# Alternatively, use this instead if you don't need to put channel ids in a secret; use a space as a separator
# You get this from https://slack.com/api/channels.list?token=REPLACE_TOKEN&pretty=1
- name: KUBEBOT_SLACK_CHANNELS_IDS
value: 'AABBCCDD'
# Specify slack admins that kubebot should listen to; use a space as a separator
- name: KUBEBOT_SLACK_ADMINS_NICKNAMES
value: 'jag test someone'
# Specify valid kubectl commands that kubebot should support; use a space as a separator
- name: KUBEBOT_SLACK_VALID_COMMANDS
value: "get describe logs explain"
Let me know if this help.