简体   繁体   English

在Kubernetes的掌舵图上为RabbitMQ创建其他虚拟主机/用户/密码

[英]Create additionals vhost/user/pass for RabbitMQ at helm chart for Kubernetes

Edit: I need to set some additionals rabbit vhost/users/pass at helm charts for a rabbitMQ we use in K8s, I tried via curl in a lifecyle postStart hook: 编辑:我需要在头盔图上为我们在K8s中使用的RabbitMQ设置一些额外的Rabbit vhost / users / pass,我通过在lifecyle postStart钩中通过curl尝试过:

Here's an example: 这是一个例子:

lifecycle:
  postStart:
    exec:
      command: ["'/bin/sh', '-c','curl -i -u guest:guest -H ''content-type:application/json'' -XPUT -d '''{'password':'1234','tags':'monitoring'}''' http://localhost:15672/api/users/deleteme'"]

But fails : 但是失败了:

Killing container with id docker://rabbitmq:FailedPostStartHook

I tried changing quotation and also setting it like: 我尝试更改报价,并将其设置为:

command:
 - "sh":
 - "-c":
 - etc....

With no success, it's the first time I'm using hooks, any advice, please? 没有成功,这是我第一次使用钩子,有什么建议吗? Thanks! 谢谢!

full statefulset: 全状态集:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: {{ .Chart.Name }}
  labels:
    app: {{ .Chart.Name }}
spec:
  serviceName: {{ .Chart.Name }}
  replicas: {{ .Values.replicaCount }}
  updateStrategy:
    type: {{ .Values.updateStrategy }}
  template:
    metadata:
      labels:
        app: {{ .Chart.Name }}
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: {{ .Chart.Name }}
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: epmd
              protocol: TCP
              containerPort: 4369
            - name: amqp
              protocol: TCP
              containerPort: 5672
            - name: http
              protocol: TCP
              containerPort: 15672
          livenessProbe:
            exec:
              command:
                - rabbitmqctl
                - status
            initialDelaySeconds: 30
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
                - rabbitmqctl
                - status
            initialDelaySeconds: 10
            timeoutSeconds: 5
          env:
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: RABBITMQ_USE_LONGNAME
              value: "true"
            - name: RABBITMQ_NODENAME
              value: "rabbit@$(MY_POD_IP)"
            - name: K8S_SERVICE_NAME
              value: {{ .Chart.Name }}
            - name: RABBITMQ_ERLANG_COOKIE
              valueFrom:
                secretKeyRef:
                  name: {{ .Chart.Name }}
                  key: rabbitmq-erlang-cookie
            - name: RABBITMQ_DEFAULT_USER
              value: {{ .Values.rabbitmqUsername | quote }}
            - name: RABBITMQ_DEFAULT_PASS
              valueFrom:
                secretKeyRef:
                  name: {{ .Chart.Name }}
                  key: rabbitmq-password
            - name: RABBITMQ_DEFAULT_VHOST
              value: {{ .Values.rabbitmqVhost | quote }}
          volumeMounts:
            - name: data
              mountPath: /var/lib/rabbitmq
            - name: config
              mountPath: /etc/rabbitmq
          lifecycle:
              postStart:
                exec:
                  command:
                  - "sh"
                  - "-c"
                  - "curl -i -u guest:guest -H \"content-type:application/json\" -XPUT -d \"{\"password\":\"1234\",\"tags\":\"monitoring\"}\" http://rabbitmq:15672/api/users/deleteme"
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchLabels:
                    app: {{ .Chart.Name }}
      volumes:
        - name: config
          configMap:
            name: {{ .Chart.Name }}
        - name: data
          emptyDir: {}

I might ending up using values or trying to set it up at configmap: https://github.com/helm/charts/tree/master/stable/rabbitmq-ha 我可能最终会使用值或尝试在configmap上进行设置: https : //github.com/helm/charts/tree/master/stable/rabbitmq-ha

If there's a better way, would be great. 如果有更好的方法,那就太好了。

I would recommend to look at Helm Hooks . 我建议看一下头盔挂钩 They consist with various options to interpose at certain phases of the development life cycle. 它们包含各种选项,可在开发生命周期的某些阶段进行干预。 Hooks represent themselves as regular templates, however they require a special annotations to be set in order Helm to interpret them correctly. 挂钩将自己表示为常规模板,但是它们需要设置特殊的注释,以便Helm正确解释它们。

apiVersion: ...
kind: ....
metadata:
  annotations:
    "helm.sh/hook": "pre-install"
# ...

You can consider to run a Job with post-install hook which executes after all resources are loaded into Kubernetes. 您可以考虑运行带有post-install挂钩的Job,该挂钩在所有资源加载到Kubernetes之后执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM