Kubernetes - 在部署时运行 chmod

Lee*_*Lee 1 yaml kubernetes

我有一个运行 Laravel 的 Kubernetes pod,但在加载时出现以下权限错误:

没有权限

如果我以交互方式访问 pod 并在 /storage 上运行 chmod:

chmod 存储

Laravel 应用程序可以运行。如何让此命令在部署时运行?我尝试了以下方法,但收到 502 nginx 错误:

apiVersion: apps/v1
kind: Deployment
metadata:
    name: app
spec:
    replicas: 1
    selector:
        matchLabels:
            container: app
    template:
        metadata:
            labels:
                container: app
        spec:
            containers:
                - name: app
                  image: my/toolkit-app:test
                  command: ["chmod -R 777 /storage"]
                  securityContext:
                      runAsUser: 0
                  ports:
                      - containerPort: 80
            imagePullSecrets:
                - name: my-cred
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以使用PostStart容器挂钩。

apiVersion: apps/v1
kind: Deployment
metadata:
    name: app
spec:
    replicas: 1
    selector:
        matchLabels:
            container: app
    template:
        metadata:
            labels:
                container: app
        spec:
            containers:
                - name: app
                  image: my/toolkit-app:test
                  securityContext:
                      runAsUser: 0
                  ports:
                      - containerPort: 80
                  lifecycle:
                      postStart:
                          exec:
                              command: ["/bin/sh", "-c", "chmod -R 777 /storage"]
            imagePullSecrets:
                - name: my-cred
Run Code Online (Sandbox Code Playgroud)

考虑一件事:

该钩子在容器创建后立即执行。但是,不能保证挂钩将在容器 ENTRYPOINT 之前执行。没有参数传递给处理程序。