Skip to content

Commit ca5e822

Browse files
authored
en: Add a doc about how to run as non root user (#2742)
1 parent 868442b commit ca5e822

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

en/TOC.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- markdownlint-disable MD007 -->
2+
<!-- markdownlint-disable MD041 -->
3+
4+
- [TiDB on Kubernetes Docs](https://docs.pingcap.com/tidb-in-kubernetes/dev)
5+
- Introduction
6+
- Deploy
7+
- On Self-Managed Kubernetes
8+
- Monitor and Alert
9+
- Migrate
10+
- Migrate from MySQL
11+
- Manage
12+
- Security
13+
- [Run Containers as a Non-Root User](containers-run-as-non-root-user.md)
14+
- Upgrade
15+
- Upgrade TiDB Operator
16+
- Backup and Restore
17+
- Amazon S3 Compatible Storage
18+
- Google Cloud Storage
19+
- Azure Blob Storage
20+
- Persistent Volumes
21+
- Snapshot Backup and Restore across Multiple Kubernetes
22+
- Maintain
23+
- Replace Nodes for a TiDB Cluster
24+
- Disaster Recovery
25+
- Troubleshoot
26+
- Reference
27+
- Architecture
28+
- Tools
29+
- Configure
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Run Containers as a Non-Root User
3+
summary: Learn how to run containers as a non-root user in a Kubernetes environment.
4+
---
5+
6+
# Run Containers as a Non-Root User
7+
8+
In some Kubernetes environments, containers cannot be run as the root user. For security reasons, it is recommended to run containers as a non-root user in production environments to reduce the risk of potential attacks. This document describes how to configure containers to run as a non-root user using the [`securityContext`](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod).
9+
10+
## Configure containers related to TiDB Operator
11+
12+
For TiDB Operator containers, configure the `securityContext` in the Helm `values.yaml` file.
13+
14+
The following is an example configuration:
15+
16+
```yaml
17+
controllerManager:
18+
securityContext:
19+
runAsUser: 1000
20+
runAsGroup: 2000
21+
fsGroup: 2000
22+
```
23+
24+
## Configure containers generated by CR
25+
26+
For containers generated by Custom Resources (CRs), configure the `securityContext` in any CR, such as `PDGroup`, `TiDBGroup`, `TiKVGroup`, `TiFlashGroup`, `TiCDCGroup`, `Backup`, `CompactBackup`, `BackupSchedule`, or `Restore`.
27+
28+
- For CRs such as `PDGroup`, `TiDBGroup`, `TiKVGroup`, `TiFlashGroup`, and `TiCDCGroup`, configure the `securityContext` using the Overlay method. The following is an example configuration for the `PDGroup` CR:
29+
30+
```yaml
31+
apiVersion: core.pingcap.com/v1alpha1
32+
kind: PDGroup
33+
metadata:
34+
name: pd
35+
spec:
36+
template:
37+
spec:
38+
overlay:
39+
pod:
40+
spec:
41+
securityContext:
42+
runAsUser: 1000
43+
runAsGroup: 2000
44+
fsGroup: 2000
45+
```
46+
47+
- For CRs such as `Backup`, `CompactBackup`, `BackupSchedule`, and `Restore`, configure the `podSecurityContext` in the `spec` field. The following is an example configuration for the `Backup` CR:
48+
49+
```yaml
50+
apiVersion: br.pingcap.com/v1alpha1
51+
kind: Backup
52+
metadata:
53+
name: backup
54+
spec:
55+
podSecurityContext:
56+
runAsUser: 1000
57+
runAsGroup: 2000
58+
fsGroup: 2000
59+
```

0 commit comments

Comments
 (0)