Skip to content

Instantly share code, notes, and snippets.

@devblackops
Last active August 29, 2022 07:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devblackops/503fd74f86683ba8a1e4b57eadd0fcb4 to your computer and use it in GitHub Desktop.
Save devblackops/503fd74f86683ba8a1e4b57eadd0fcb4 to your computer and use it in GitHub Desktop.
PoshBot container in Kubernetes
# config map
apiVersion: v1
kind: ConfigMap
metadata:
name: poshbot-config
namespace: default
data:
POSHBOT_ADMINS: devblackops
# POSHBOT_NAME:
# POSHBOT_CONFIG_DIRECTORY:
# POSHBOT_LOG_DIRECTORY:
# POSHBOT_PLUGIN_DIRECTORY:
# POSHBOT_PLUGIN_REPOSITORIES:
# POSHBOT_LOG_LEVEL:
# POSHBOT_MAX_LOG_SIZE_MB:
# POSHBOT_MAX_LOGS_TO_KEEP:
# POSHBOT_LOG_CMD_HISTORY:
# POSHBOT_CMD_HISTORY_MAX_LOG_SIZE_MB:
# POSHBOT_CMD_HISTORY_MAX_LOGS_TO_KEEP:
# POSHBOT_BACKEND_CONFIGURATION:
# POSHBOT_PLUGIN_CONFIGURATION:
# POSHBOT_CMD_PREFIX:
# POSHBOT_ALT_CMD_PREFIXES:
# POSHBOT_ALT_CMD_PREFIX_SEP:
# POSHBOT_SEND_CMD_RESP_TO_PRIV:
# POSHBOT_MUTE_UNKNOWN_CMD:
# POSHBOT_ADD_CMD_REACTIONS:
# POSHBOT_DISALLOW_DMS:
# POSHBOT_FORMAT_ENUMERATION_LIMIT:
# POSHBOT_CONF_DIR:
# POSHBOT_BACKEND:
# Slack vars (get from secret)
# POSHBOT_SLACK_TOKEN:
# Teams vars
# POSHBOT_TEAMS_BOT_NAME:
# POSHBOT_TEAMS_ID:
# POSHBOT_TEAMS_SERVICEBUS_NAMESPACE:
# POSHBOT_TEAMS_SERVICEBUS_QUEUE_NAME:
# POSHBOT_TEAMS_SERVICEBUS_ACCESS_KEY_NAME:
# (get from secret)
# POSHBOT_TEAMS_SERVICEBUS_ACCESS_KEY:
# POSHBOT_BOT_FRAMEWORK_ID:
# (get from secret)
# POSHBOT_BOT_FRAMEWORK_PASSWORD:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: poshbot-deployment
spec:
selector:
matchLabels:
app: poshbot
replicas: 1
template:
metadata:
labels:
app: poshbot
version: 0.11.3
spec:
containers:
- name: poshbot
image: poshbotio/poshbot:ubuntu16.04-0.11.3
volumeMounts:
- mountPath: /poshbot_data
name: pb-data
- mountPath: /root/.local/share/powershell/Modules
name: pb-modules
envFrom:
- configMapRef:
name: poshbot-config
env:
- name: POSHBOT_SLACK_TOKEN
valueFrom:
secretKeyRef:
name: poshbot-slack-token-secret
key: slack_token.txt
volumes:
- name: pb-data
persistentVolumeClaim:
claimName: poshbot-pvc
- name: pb-modules
persistentVolumeClaim:
claimName: poshbot-pvc2
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: poshbot-pv001
spec:
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: hostpath
capacity:
storage: 500Mi
hostPath:
path: /data/poshbot-pv001/
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: poshbot-pv002
spec:
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: hostpath
capacity:
storage: 500Mi
hostPath:
path: /data/poshbot-pv002/
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: poshbot-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: poshbot-pvc2
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi

PoshBot and Kubernetes

This gist is a quick example of how to run PoshBot inside Kubernetes using minikube. This will deploy PoshBot v0.11.3 inside a Linux container and expose most configuration options as environment variables. The Slack bot token is stored as a Kubernetes secret.

Secrets

Create a Kubernetes secret which includes your Slack bot token. This secret will be later be exposed to the pod as the POSHBOT_SLACK_TOKEN environment variable.

echo -n '<SLACK-TOKEN>' > ./slack_token.txt
kubectl create secret generic poshbot-slack-token-secret --from-file ./slack_token.txt

Deployment

Most PoshBot configuration options are exposed as environment variables which you can set in from the ConfigMap in the yaml file. To enable persistence, the deployment creates two volumes that mount to /poshbot_data and /root/.local/share/powershell/Modules in the container. Mounting a volume for the modules directory ensures any plugins installed persist across container restarts.

kubectl apply -f ./poshbot.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment