<p>I want to run this docker image in kubernetes:
<a href="https://hub.docker.com/_/rabbitmq" rel="nofollow noreferrer">https://hub.docker.com/_/rabbitmq</a></p>
<p>This is not a problem, and it is running. The problem is that I need to send through switches do the &quot;docker run&quot; command. For this image, when starting the container in docker you would run this:</p>
<pre><code>docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3
</code></pre>
<p>The yaml file will then look something like this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:  
  name: rb
  namespace: rabbittest
spec:
  selector:
    matchLabels:
        app: rb
  replicas: 1
  template:
    metadata:
      labels:
        app: rb
    spec:
      containers:
      - name: rb-container
        env:                    
          - name: HOSTNAME
            value: &quot;rbnode001&quot;
        image: rabbitmq:3-management        
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        volumeMounts:
          - name: azure
            mountPath: /mnt/azure
        ports:
          - containerPort: 5672
      volumes:
      - name: azure
        azureFile:
          secretName: azure-secret
          shareName: rabbittest
          readOnly: false
</code></pre>
<p>My question is, how do I get kubernetes to apply the --name and --hostname when kubernetes executes the &quot;docker run&quot; commands?</p>

Bertus van Zyl
<p>First of all, you need to create <code>StatefulSets</code> to <code>RabbitMQ</code>.</p>
<p>In your StatefulSet, add this <code>ENV</code>.</p>
<pre><code>env:
  - name: POD_NAME
    valueFrom:
      fieldRef:
        apiVersion: v1
        fieldPath: metadata.name
  - name: POD_NAMESPACE
    valueFrom:
      fieldRef:
        apiVersion: v1
        fieldPath: metadata.namespace
  - name: K8S_SERVICE_NAME
    value: rabbitmq-headless
  - name: RABBITMQ_NODENAME
    value: $(POD_NAME).$(K8S_SERVICE_NAME).$(POD_NAMESPACE).svc.cluster.local
</code></pre>
<p>Here, <code>K8S_SERVICE_NAME</code> is headless service required by statefulset.</p>
<p>Finally, <code>RABBITMQ_NODENAME</code> will hold the HOSTNAME.</p>
