Skip to content

Instantly share code, notes, and snippets.

@j-griffith
Last active February 2, 2022 16:45
Show Gist options
  • Save j-griffith/f82bd567dc963ff953adcc44d0ebd96e to your computer and use it in GitHub Desktop.
Save j-griffith/f82bd567dc963ff953adcc44d0ebd96e to your computer and use it in GitHub Desktop.
Docker iscsi in container run cmd
# This will use the hosts iscsid
docker run -it --net=host --privileged -v /etc/localtime:/etc/localtime:ro \
-v /lib/modules:/lib/modules:ro \
-v /run:/run:shared -v /dev:/dev \
-v /etc/iscsi:/etc/iscsi \
-v /home/jgriffith/vol:/Mount:shared ubuntu bash
# shared declaration on Mount matters!
# You can also put iscsid in another container, share the socket
# BUT make sure you do NOT run the iscsid on the host node
@johnjoji
Copy link

johnjoji commented Mar 25, 2018

Hey John,

Would this allow me to define unique iSCSI initiatornames per docker container or am I still tied to docker host's iqn?
Yes, it does. I wasn't doing my RTFM.

I made a wee change in the bind mappings from
-v /etc/iscsi:/etc/iscsi to -v /root/iscsi1:/etc/iscsi in an attempt to not touch the host iscsi config. I copied iscsid.conf from /etc/iscsi to /root/iscsi1
I could run iscsid in the container with my own iqn. Now, to see if I can run multiple!
Cheers.

@princerachit
Copy link

Is it possible to run iscsid in a k8s' pod's container? What flags do I need to pass in that case (assuming that the container runs in privileged mode)?

@kvaps
Copy link

kvaps commented Jun 2, 2018

@princerachit, I have success with that:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: iscsi
spec:
  updateStrategy:
    type: OnDelete
  selector:
    matchLabels:
      app: iscsi
  template:
    metadata:
      labels:
        app: iscsi
    spec:
      hostNetwork: true

      initContainers:
      - name: install
        image: "kvaps/iscsi"
        command:
        - cp
        args:
        - -f
        - /usr/bin/iscsiadm
        - /usr/sbin/tgtadm
        - /host-bin
        volumeMounts:
        - name: bin
          mountPath: /host-bin

      containers:
      - name: tgtd
        imagePullPolicy: Always
        image: "kvaps/iscsi"
        command: [ "tgtd", "-f" ]
        securityContext:
          privileged: true
        volumeMounts:
        - name: run
          mountPath: "/run"
      - name: iscsid
        imagePullPolicy: Always
        image: "kvaps/iscsi"
        command: [ "iscsid", "-f" ]
        securityContext:
          privileged: true
        volumeMounts:
        - name: modules
          mountPath: "/lib/modules"
        - name: dev
          mountPath: "/dev"
        - name: run
          mountPath: "/run"

      volumes:
      - name: modules
        hostPath:
          path: "/lib/modules"
      - name: run
        hostPath:
          path: "/run"
      - name: dev
        hostPath:
          path: "/dev"
      - name: bin
        hostPath:
          path: "/usr/local/bin"

@j-griffith
Copy link
Author

Nice, thanks for adding that @kvaps ! I'm afraid I never noticed the comments on this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment