从另一个Pod更改kubernetes阻止类安装值 [英] Change kubernetes stroge class mounted value from another pod

查看:99
本文介绍了从另一个Pod更改kubernetes阻止类安装值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用kubernetes发布声纳尔.我成功完成了官方套餐.但是我想使用一些旧版本的插件和一些自定义插件.在带有docker-compose文件的本地文件中,我创建了一个可飞走的容器,其中用插件填充了插件目录(/opt/sonarqube/extensions/plugins).并将其与声纳容器一起使用.结论是:Sonarqube扩展卷目录是通过不同的容器创建(或填充)的(执行此操作并消亡).

I want to publish sonarqube with kubernetes. I did successfully with official packages. But i want to use some plugins old version and some custom plugins. In local with docker-compose files, i created a fly-away container that fills the plugins directory(/opt/sonarqube/extensions/plugins) with plugins. And use that volume with sonarqube container. As a conclusion : Sonarqube extensions volume directory is created (or filled) from different container(do the job and die).

我想对kubernetes使用相同的路径,但不能这样做.我的飞车容器没有塞满路径.

I want to use the same path with kubernetes but couldn't do that. My flyaway container didn't fill the path.

我的kubernetes部署文件:

My kubernetes deployments files:

1-)sonar-pvc-extensions.yml

1-) sonar-pvc-extensions.yml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: claim-sonar-extensions
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi

2-)sonarqube-deployment.yml

2-) sonarqube-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarqube
spec:
  replicas: 1
  selector:
    matchLabels:
      name: sonarqube
  template:
    metadata:
      name: sonarqube
      labels:
        name: sonarqube
    spec:
      containers:
        - image: sonarqube:7.9.1-community
          name: sonarqube
          env:
            - name: SONARQUBE_JDBC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-pwd
                  key: password
            - name: SONARQUBE_JDBC_URL
              value: jdbc:postgresql://sonar-postgres:5432/sonar
          ports:
            - containerPort: 9000
              name: sonarqube
          volumeMounts:               
            - name: data-sonar-extensions
              mountPath: /opt/sonarqube/extensions/plugins
          resources:
            requests:
              memory: 2000Mi
            limits:
              memory: 2000Mi
      volumes:
        - name: data-sonar-extensions
          persistentVolumeClaim:
            claimName: claim-sonar-extensions
      initContainers:
        - name: sysctl
          image: busybox
          imagePullPolicy: IfNotPresent
          command: ['sysctl', '-w', 'vm.max_map_count=262144']
          securityContext:
            privileged: true

3-)示例插件Dockerfile

3-)Sample plugins Dockerfile

FROM alpine:3.4

RUN apk --no-cache add --repository http://dl-cdn.alpinelinux.org/alpine/edge/community wget ca-certificates

ENV PLUGINS_DIR /opt/sonarqube/extensions/plugins

WORKDIR $PLUGINS_DIR
RUN wget https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/4.1.0-SNAPSHOT/sonar-gitlab-plugin-4.1.0-SNAPSHOT.jar
RUN wget https://binaries.sonarsource.com/Distribution/sonar-java-plugin/sonar-java-plugin-6.3.0.21585.jar
RUN wget https://github.com/SonarSource/sonar-php/releases/download/3.4.0.5461/sonar-php-plugin-3.4.0.5461.jar
ENV JAVASCRIPT_VERSION 2.20.0.4207

VOLUME $PLUGINS_DIR

CMD ls -asl $PLUGINS_DIR

我用sonar-plugin-deployment.yml尝试了这种方法:

I tried that approach with sonar-plugin-deployment.yml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarqube-plugin
spec:
  replicas: 1
  selector:
    matchLabels:
      name: sonarqube-plugin
  template:
    metadata:
      name: sonarqube-plugin
      labels:
        name: sonarqube-plugin
    spec:
      containers:
        - image: my-kubernetes-registry/plugins
          name: sonarqube-plugins
          volumeMounts:
            # This name must match the volumes.name below.
            - name: data-sonar-extensions
              mountPath: /opt/sonarqube/extensions/plugins
      volumes:
        - name: data-sonar-extensions
          persistentVolumeClaim:
            claimName: claim-sonar-extensions

但是没有成功.弄点东西这次我的插件目录变为空:

But didn't successed. And break something. This time my plugins directory became empty:

sonarqube@sonarqube-85b98d9845-l2sql:/opt/sonarqube/extensions/plugins$ ls -al
total 24
drwxr-xr-x 3 root      root       4096 May 30 16:19 .
drwxr-xr-x 1 sonarqube sonarqube  4096 May 30 16:39 ..
drwx------ 2 root      root      16384 May 30 16:19 lost+found

我没有使用永久卷. PVC正在寻求加强.所以我不能使用accessModes作为ReadWriteMany.

I am not using persistent volume. PVC is looking to stroge class. So i cant use accessModes as ReadWriteMany.

结果:我想使用可飞走的容器更改转弯路径,并在应用程序中使用该路径.

As a results: I want to change a stroge path with a fly-away container and use that path inside an app.

如果您建议采用其他方法,我将对kubernetes不满意.

I am noob to kubernetes if you suggest a different approach i will be apreciated.

推荐答案

检查初始化容器应适合您的需求.

您可以使用init容器填充数据,完成后即可在此数据上运行应用.

You can populate volume with data using init container and when it's done you can run your app on this data.

这篇关于从另一个Pod更改kubernetes阻止类安装值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆