在 Kubernetes(k8s)里“部署 CentOS” 通常不是把 CentOS 当宿主机系统装进 k8s,而是 以 CentOS 为基础镜像,启动一个 Pod / Deployment,用来跑一些需要 CentOS 环境的任务(比如编译、测试、运维工具)。
下面按常见使用场景给你说明步骤。
确保你已经具备:
kubectlapiVersion: v1
kind: Pod
metadata:
name: centos-pod
spec:
containers:
- name: centos
image: centos:7
command: ["sleep", "infinity"]
sleep infinity是为了让 Pod 不退出
kubectl apply -f centos-pod.yaml
kubectl exec -it centos-pod -- bash
✅ 现在你已经在 CentOS 环境里了
适合长期运行或需要扩展的场景。
apiVersion: apps/v1
kind: Deployment
metadata:
name: centos-deploy
spec:
replicas: 1
selector:
matchLabels:
app: centos
template:
metadata:
labels:
app: centos
spec:
containers:
- name: centos
image: centos:7
command: ["sleep", "infinity"]
kubectl apply -f centos-deploy.yaml
如果需要在 CentOS 里保存数据:
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: centos-pvc
K8s 官方也常用这种方式:
kubectl run centos --image=centos:7 --restart=Never -- sleep infinity
kubectl exec -it centos -- bash
✅ CentOS 在 k8s 里 只是容器,不是虚拟机 ✅ 没有 systemd(除非特殊配置) ✅ 不建议跑数据库、Web 服务等“正经业务” ✅ 更适合:
那是另一回事:
kubeadm init / join 安装如果你能告诉我:
我可以给你更精确的方案(含 YAML / 网络 / 存储)。