使用作业 Pod 写入 PVC 的数据在主 POD 中不可用

使用作业 Pod 写入 PVC 的数据在主 POD 中不可用

我有一个带有 bash 脚本的作业 pod,该脚本可执行并将数据写入 PVC,但是,当我从主 POD 签入时,相同的数据不可用,部署和作业都使用相同的 PVC,它是读写许多部署文件

apiVersion: apps/v1 
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: magento-service
  template:
    metadata:
      labels:
        app: magento-service
    spec:
      containers:
        - name: magento
          image: adobemagento2/magento473
          ports:
            - containerPort: 80
            - containerPort: 9000
          envFrom:
           - configMapRef:
               name: mag-config
          volumeMounts:
            - name: web
              mountPath: "/var/www/html/pub/media"

      volumes:
        - name: web
          persistentVolumeClaim:
            claimName: magento-pvc
      imagePullSecrets:
        - name: regcred

作业文件


apiVersion: batch/v1 
kind: Job
metadata:
  name: example-job
spec:
  template:
    metadata:
      name: example-job
    spec:
      containers:
      - name: example-container
        image: adobemagento2/magento473
        command: ["sh", "-c", "bin/install.sh"]
        envFrom:
         - configMapRef:
             name: mag-config
        volumeMounts:
        - name: web
          mountPath: "/var/www/html/pub/media"
          


      restartPolicy: Never
      imagePullSecrets:
        - name: regcred
      volumes:
      - name: web
        persistentVolumeClaim:
          claimName: magento-pvc

Dockerfile


FROM php:8.2.12-fpm@sha256:2aa938b6d62f7415e9c84d867d9ceed18ef8ec3cf3944d389e088c93f9678a84 
ENV DOC_ROOT /var/www/html
ENV COMPOSER_HOME=/tmp/composer
WORKDIR /var/www/html
#ENV MAGENTO_VERSION 2.4.6-p3


#RUN apt-get update && apt-get install -y --no-install-recommends gnupg \
#RUN apt-get install -y gnupg1
#RUN echo "deb http://nginx.org/packages/mainline/debian buster nginx" >> /etc/apt/sources.list.d/nginx.list
#RUN curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
#RUN apt-get update && apt-get install -y nginx=1.24.*



RUN apt-get update && apt-get install -y --no-install-recommends gnupg \
    netcat-openbsd \
    nginx \
    sudo \
    libicu-dev \
    libfreetype6-dev \
    libjpeg-dev \
    libpng-dev \
    libsodium-dev \
    libxml2-dev \
    libxslt-dev \
    libzip-dev \
    rsync \
    supervisor \
    unzip \
    cron \
    default-mysql-client \
    git \
    gnupg \
    gzip \
    libbz2-dev \
    libfreetype6-dev \
    libicu-dev \
    libjpeg62-turbo-dev \
    libmagickwand-dev \
    libmcrypt-dev \
    libonig-dev \
    libpng-dev \
    libsodium-dev \
    libssh2-1-dev \
    libwebp-dev \
    libxslt1-dev \
    libzip-dev \
    lsof \
    mailutils \
    msmtp \
    procps \
    vim \
    zip \
  && rm -rf /var/lib/apt/lists/*



#RUN echo "deb http://nginx.org/packages/mainline/debian buster nginx" >> /etc/apt/sources.list.d/nginx.list
#RUN curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
#RUN apt-get update && apt-get install -y nginx

RUN pecl install apcu-5.1.22

RUN docker-php-ext-configure \
    gd --with-freetype --with-jpeg --with-webp \
  && docker-php-ext-install \
    bcmath \
    bz2 \
    calendar \
    exif \
    gd \
    gettext \
    intl \
    mbstring \
    mysqli \
    opcache \
    pcntl \
    pdo_mysql \
    soap \
    sockets \
    sodium \
    sysvmsg \
    sysvsem \
    sysvshm \
    xsl \
    zip 



RUN mkdir -p /var/run && \
    chown -R www-data:www-data /var/run
#WORKDIR /var/www/html


COPY  magento /etc/cron.d/cronjob
COPY  sslcript.sh /usr/local/bin
RUN chmod +x /usr/local/bin/sslcript.sh
RUN chown www-data:www-data /etc/cron.d/cronjob
#COPY auth.json /var/www/html/magento/auth.json 
RUN chmod 0644 /etc/cron.d/cronjob
RUN crontab /etc/cron.d/cronjob
RUN touch /var/log/cron.log

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

#RUN docker-php-ext-enable apcu

RUN echo "memory_limit=1G" >> /usr/local/etc/php/conf.d/zz-memory-limit-php.ini
RUN echo "apc.enable=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "opcache.memory_consumption=512MB" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.max_accelerated_files=60000" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.consistency_checks=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.validate_timestamps=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-opcache.conf

RUN mkdir -p /var/lib/nginx/{body,fastcgi} && \
    chown -R www-data:www-data /var/lib/nginx

RUN touch /run/nginx.pid && \
    chown www-data:www-data /run/nginx.pid
RUN chown www-data:www-data /var/log/nginx/error.log
RUN chown www-data:www-data /var/log/nginx/access.log



COPY etc/nginx /etc/nginx




ARG COMPOSER_AUTH

COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer
COPY --chown=www-data magento.
RUN cd /var/www/html  && composer install 

COPY --chown=www-data bin bin


ENV MAGE_MODE=developer
EXPOSE 80

CMD service cron start && service nginx start && php-fpm

PVC 舱单



apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: magento-pvc
  #  namespace: kube-system
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
  storageClassName: rook-cephfs

相关内容