How to successfully start open-iscsi service on Ubuntu 20.04

ISCSI is an protocol that transports block level data across a network, between an ISCSI Initiator (client) and ISCSI target on a storage device. When setting up a Kubernetes Cluster, some storage solutions such as Longhorn and OpenEBS require ISCSI service to be running. This guide shows you how to make the service start on single node kubernetes cluster

We assume you have already installed open-iscsi service on an Ubuntu 20.04 system

1.Setup ISCSI username and password

  • Edit the /etc/iscsi/iscsid.conf file
    vim /etc/iscsi/iscsid.conf
  • Uncomment the following, set your preferred username and password
node.session.auth.authmethod = CHAP
node.session.auth.username = mwabini
node.session.auth.password = E3i2aPsJB4F6USt
discovery.sendtargets.auth.username = mwabini
discovery.sendtargets.auth.password = E3i2aPsJB4F6USt

2. Install ISCSI Target

  • install tgt service
    root@vmi663745:~# apt install tgt -y
  • start and enable tgt
    root@vmi663745:~# systemctl start tgt; systemctl enable tgt

3. Edit ISCSI initiator name. Edit the file name below

vim /etc/iscsi/initiatorname.iscsi

The default initiator name will be something like

iqn.1993-08.org.debian:01:bce928e8349

Change that to the name below

iqn.2021-10.rawle:ubuntu1.initiator01

4. Create and configure an ISCSI initiator config file

  • Create the file below
    vim /etc/tgt/conf.d/k8s_iscsi.conf
  • Copy the contents below into the file. Change the initiator-address to your VPS IP. The incominguser and outgoinguser are as defined in Step 1 above
<target iqn.2021-10.rawle:ubuntu1.initiator01>
     initiator-address 10.10.10.10
     incominguser mwabini E3i2aPsJB4F6USt
     outgoinguser mwabini E3i2aPsJB4F6USt
</target>

5. Restart services so as to pick changes

systemctl restart tgt
systemctl restart iscsid

6. Run discovery, output should be as below

root@vmi663745:~# iscsiadm -m discovery -t st -p 10.10.10.10
10.10.10.10:3260,1 iqn.2021-10.rawle:ubuntu1.initiator01

7. Login to iscsid, output should be as below

root@vmi663745:~# iscsiadm -m node --login
Logging in to iface: default, target: iqn.2021-10.rawle:ubuntu1.initiator01, portal: 10.10.10.10,3260
Login to [iface: default, target: iqn.2021-10.rawle:ubuntu1.initiator01, portal: 10.10.10.10,3260] successful.

8. Now restart open-iscsi and enable it, then check status

root@vmi663745:~# systemctl restart open-iscsi; systemctl enable open-iscsi
Synchronizing state of open-iscsi.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable open-iscsi

root@vmi663745:~# systemctl status open-iscsi
● open-iscsi.service - Login to default iSCSI targets
     Loaded: loaded (/lib/systemd/system/open-iscsi.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2021-10-11 16:22:32 CEST; 14s ago
       Docs: man:iscsiadm(8)
             man:iscsid(8)
   Main PID: 83083 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 9485)
     Memory: 0B
     CGroup: /system.slice/open-iscsi.service

Troubleshoot

If in an attempt to discover the Target as in step 6 above, you get an error on Login failed, please double check the steps above especially on configuration of credentials and ensure they are correct to resolve the matter.

Leave a Reply

Your email address will not be published. Required fields are marked *