Skip to content

Commit bdb1df2

Browse files
authored
executors: add manifests for native executors (sourcegraph#4255)
* executors: add manifests for native executors * Finish readme, implement -1 sentinel values
1 parent 25ee00c commit bdb1df2

11 files changed

+226
-4
lines changed

configure/executors/README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,42 @@ This directory contains manifests for the optional deployment of Sourcegraph Exe
88

99
It is expected that all components contained in this directory and any subdirectories are deployed to ensure full functionality and best performance.
1010

11+
There are two distribution methods supported:
12+
13+
### Native Kubernetes Executors (Recommended)
14+
Requirements: RBAC, persistent volumes
15+
16+
This distribution method makes use of native Kubernetes Deployments, Services, and Jobs to execute workloads. It is suitable for clusters that meet Sourcegraph's minimum requirements.
17+
1118
The following components will deployed:
19+
- [Executor Deployment](./executor/k8s/executor.Deployment.yaml) An Executor replica with a Docker sidecar to run isolated batch changes and auto-indexing jobs. This deployment requires a [privileged security context](https://kubernetes.io/docs/concepts/security/pod-security-standards/).
20+
- [Executor Service](./executor/k8s/executor.Service.yaml) A headless service for executor metrics access. Executors are not externally accessible.
21+
- [Executor ConfigMap](./executor/k8s/executor.ConfigMap.yaml) configuration for the Executor deployment
22+
- RBAC
23+
- [Role](./executor/k8s/rbac/executor.Role.yaml)
24+
- [RoleBinding](./executor/k8s/rbac/executor.RoleBinding.yaml)
25+
- [ServiceAccount](./executor/k8s/rbac/executor.ServiceAccount.yaml)
26+
- [Private docker registory]
27+
- [Registry Deployment](./private-docker-registry/private-docker-registry.Deployment.yaml) A private docker registry configured as a pull-through cache to avoid docker hub rate limiting.
28+
- [Registry Service](./private-docker-registry/private-docker-registry.Service.yaml) A service to access the private-docker-registry.
29+
- [Registry Persistent Volume](./private-docker-registry/private-docker-registry.PersistentVolumeClaim.yaml) A volume to store images in the private-docker-registry.
1230

13-
- [Executor Deployment](./executor/executor.Deployment.yaml) An Executor replica with a Docker sidecar to run isolated batch changes and auto-indexing jobs. This deployment requires a [privileged security context](https://kubernetes.io/docs/concepts/security/pod-security-standards/).
14-
- [Executor Service](./executor/executor.Service.yaml) A headless service for executor metrics access. Executors are not externally accessible.
15-
- [Docker ConfigMap](./executor/docker-daemon.ConfigMap.yaml) configuration for the docker sidecar to use the pull-through cache.
31+
To apply these manifests, run the following command:
32+
33+
```bash
34+
kubectl apply -f . --recursive private-docker-registry
35+
kubectl apply -f . --recursive k8s
36+
```
37+
38+
### Docker-in-Docker Kubernetes Executors
39+
Requirements: elevated permissions, persistent volumes
40+
41+
This distribution method makes use of a docker-in-docker sidecar container to execute the workloads. It is suitable for clusters that meet Sourcegraph's minimum requirements that cannot utilize native Kubenretes executors.
42+
43+
The following components will deployed:
44+
- [Executor Deployment](./executor/dind/executor.Deployment.yaml) An Executor replica with a Docker sidecar to run isolated batch changes and auto-indexing jobs. This deployment requires a [privileged security context](https://kubernetes.io/docs/concepts/security/pod-security-standards/).
45+
- [Executor Service](./executor/dind/executor.Service.yaml) A headless service for executor metrics access. Executors are not externally accessible.
46+
- [Docker ConfigMap](./executor/dind/docker-daemon.ConfigMap.yaml) configuration for the docker sidecar to use the pull-through cache.
1647
- [Private docker registory]
1748
- [Registry Deployment](./private-docker-registry/private-docker-registry.Deployment.yaml) A private docker registry configured as a pull-through cache to avoid docker hub rate limiting.
1849
- [Registry Service](./private-docker-registry/private-docker-registry.Service.yaml) A service to access the private-docker-registry.
@@ -21,6 +52,7 @@ The following components will deployed:
2152
To apply these manifests, run the following command:
2253

2354
```bash
24-
kubectl apply -f . --recursive
55+
kubectl apply -f . --recursive private-docker-registry
56+
kubectl apply -f . --recursive dind
2557
```
2658

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: executor-config
6+
labels:
7+
app: executor
8+
deploy: sourcegraph
9+
sourcegraph-resource-requires: no-cluster-admin
10+
app.kubernetes.io/component: executor
11+
# Refer to https://docs.sourcegraph.com/admin/executors/deploy_executors_binary#step-2-setup-environment-variables on how to populate these variables
12+
data:
13+
EXECUTOR_USE_FIRECRACKER: "false"
14+
EXECUTOR_KUBERNETES_PERSISTENCE_VOLUME_NAME: "sg-executor-pvc"
15+
EXECUTOR_KUBERNETES_POD_AFFINITY: '[{"labelSelector": {"matchExpressions": [{"key": "app", "operator": "In", "values": ["executor"]}]}, "topologyKey": "kubernetes.io/hostname"}]'
16+
# If Sourcegraph is not deployed in the `default` namespace, update this value
17+
EXECUTOR_FRONTEND_URL: "http://sourcegraph-frontend.default.svc.cluster.local:30080"
18+
EXECUTOR_MAXIMUM_NUM_JOBS: "8"
19+
# Used configure which queues Executors will process.
20+
# Can be "batches" or "codeintel"
21+
# Either set this or EXECUTOR_QUEUE_NAMES.
22+
# EXECUTOR_QUEUE_NAME: "codeintel"
23+
# Used configure which queues Executors will process.
24+
# Can be "batches" or "codeintel" or "batches,codeintel"
25+
# Either set this or EXECUTOR_QUEUE_NAME.
26+
EXECUTOR_QUEUE_NAMES: "batches,codeintel"
27+
EXECUTOR_KUBERNETES_RESOURCE_REQUEST_MEMORY: "5Gi"
28+
# KUBERNETES_RUN_AS_USER: "-1"
29+
# KUBERNETES_RUN_AS_GROUP: "-1"
30+
# KUBERNETES_FS_GROUP: "1000"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: executor
6+
annotations:
7+
description: Runs sourcegraph executor replicas for batch changes and codeintel auto indexing.
8+
kubectl.kubernetes.io/default-container: executor
9+
labels:
10+
deploy: sourcegraph
11+
sourcegraph-resource-requires: no-cluster-admin
12+
app.kubernetes.io/component: executor
13+
spec:
14+
selector:
15+
matchLabels:
16+
app: executor
17+
minReadySeconds: 10
18+
replicas: 1
19+
revisionHistoryLimit: 10
20+
strategy:
21+
rollingUpdate:
22+
maxSurge: 1
23+
maxUnavailable: 1
24+
type: RollingUpdate
25+
template:
26+
metadata:
27+
labels:
28+
app: executor
29+
spec:
30+
serviceAccountName: executor
31+
containers:
32+
- name: executor
33+
image: index.docker.io/sourcegraph/executor-kubernetes:5.1_230340_2023-06-23_5.0-93d39d620e83@sha256:172770133661d4d148327d2cac87c051a6409871ee6f6e28ce3495b60f883ad5
34+
imagePullPolicy: Always
35+
livenessProbe:
36+
exec:
37+
command:
38+
- /usr/bin/pgrep
39+
- -f
40+
- /usr/local/bin/executor
41+
initialDelaySeconds: 15
42+
timeoutSeconds: 5
43+
readinessProbe:
44+
exec:
45+
command:
46+
- /usr/bin/pgrep
47+
- -f
48+
- /usr/local/bin/executor
49+
periodSeconds: 5
50+
terminationMessagePolicy: FallbackToLogsOnError
51+
env:
52+
- name: EXECUTOR_FRONTEND_PASSWORD
53+
valueFrom:
54+
secretKeyRef:
55+
name: executor-secret
56+
key: password
57+
# Refer to https://docs.sourcegraph.com/admin/executors/deploy_executors_binary#step-2-setup-environment-variables on how to populate these variables
58+
envFrom:
59+
- configMapRef:
60+
name: executor-config
61+
volumeMounts:
62+
- mountPath: /data
63+
name: sg-executor-volume
64+
volumes:
65+
- name: sg-executor-volume
66+
persistentVolumeClaim:
67+
claimName: sg-executor-pvc
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: sg-executor-pvc
6+
labels:
7+
deploy: sourcegraph
8+
sourcegraph-resource-requires: no-cluster-admin
9+
app.kubernetes.io/component: executor
10+
spec:
11+
accessModes:
12+
- ReadWriteOnce
13+
resources:
14+
requests:
15+
storage: 100Gi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
annotations:
6+
prometheus.io/port: "6060"
7+
sourcegraph.prometheus/scrape: "true"
8+
labels:
9+
app: executor
10+
deploy: sourcegraph
11+
sourcegraph-resource-requires: no-cluster-admin
12+
app.kubernetes.io/component: executor
13+
name: executor
14+
spec:
15+
ports:
16+
- name: debug
17+
port: 6060
18+
targetPort: debug
19+
selector:
20+
app: executor
21+
type: ClusterIP
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: executor
6+
labels:
7+
category: rbac
8+
deploy: sourcegraph
9+
sourcegraph-resource-requires: cluster-admin
10+
app.kubernetes.io/component: executor
11+
rules:
12+
# Executors create Job pods to run processes. Once Jobs are completed, they are cleaned up.
13+
- apiGroups:
14+
- batch
15+
resources:
16+
- jobs
17+
verbs:
18+
- create
19+
- delete
20+
# Executors need to look up and steam logs from the Job Pods.
21+
- apiGroups:
22+
- ""
23+
resources:
24+
- pods
25+
- pods/log
26+
verbs:
27+
- get
28+
- list
29+
- watch
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: sg-executor-role-binding
6+
labels:
7+
category: rbac
8+
deploy: sourcegraph
9+
sourcegraph-resource-requires: cluster-admin
10+
app.kubernetes.io/component: executor
11+
subjects:
12+
- kind: ServiceAccount
13+
name: executor
14+
namespace: default
15+
roleRef:
16+
apiGroup: "rbac.authorization.k8s.io"
17+
kind: Role
18+
name: executor

0 commit comments

Comments
 (0)