前置き
UbuntuでiSCSIを使用する方法は以下のサイトを参照する。
https://www.server-world.info/query?os=Ubuntu_18.04&p=iscsi&f=1
Kuberenetesネットワークの設定は省略
iscsiを立てたサーバのIPは192.168.0.120とし、ホスト名はk8s-nasである
マウントするディスクはXFSでフォーマットする
フォルダ構成
以下のフォルダ構成を行う
./
├── iscsi-chap-secret.yaml
├── iscsi-provisioner-pv.yaml
├── iscsi-provisioner-pvc.yaml
└── pod
└── iscsi-test-pod.yaml
ファイル説明
パスワード定義設定
ユーザーネームがusernameでパスワードがpasswordのときは以下の通り記載する。
iscsi-chap-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: iscsi-targetd-chap-secret
type: "kubernetes.io/iscsi-chap"
data:
discovery.sendtargets.auth.username: dXNlcm5hbWUK
discovery.sendtargets.auth.password: cGFzc3dvcmQK
補足として、base64のエンコードコマンドをいかに記載する。
$ echo username |base64
dXNlcm5hbWUK
$ echo password |base64
cGFzc3dvcmQK
PersistentVolume設定
iscsi-provisioner-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: iscsi-pv
spec:
capacity:
storage: 10Gi
persistentVolumeReclaimPolicy: Retain
accessModes:
- ReadWriteOnce
iscsi:
targetPortal: 192.168.0.120:3260
iqn: iqn.2020-10.local:k8s-nas.target01
lun: 1
# fsType: ext4
fsType: xfs
chapAuthDiscovery: true
chapAuthSession: true
readOnly: false
secretRef:
name: iscsi-targetd-chap-secret
PersistentVolumeClaim設定
iscsi-provisioner-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
annotations:
volume.beta.kubernetes.io/persistent-volume: iscsi-pv
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
接続用podの設定
podにiscsiをマウントする。
iscsi-test-pod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
test: iscsi-pvc-pod
name: iscsi-pv-pod1
spec:
securityContext:
fsGroup: 1001
containers:
- name: iscsi-pv-busybox
image: busybox
command: ["/bin/sh", "-c"]
args: [ "tail -f /dev/null" ]
securityContext:
runAsUser: 1009
volumeMounts:
- name: iscsi-vol1
mountPath: /var/lib/busybox
readOnly: false
volumes:
- name: iscsi-vol1
persistentVolumeClaim:
claimName: myclaim
起動方法について
kubectl apply -f ./
kubectl apply -f ./pod/iscsi-test-pod.yaml
動作確認
以下のコマンドでpodで内に入る
kubectl exec -it pod/iscsi-pv-pod1 /bin/ash
以下のコマンドで、永続ストレージ部分にデータを保存をする。
echo Hello > /var/lib/busybox/test.txt
masterにiscsiにマウントディスク内容を調べるとtext.txtが作成される。