*https://microk8s.io/
*https://kubernetes.io/
*https://kubernetes.io/docs/tutorials/kubernetes-basics/
==基本操作==
===Document===
*[https://kubernetes.io/docs/tutorials/ チュートリアル]
*[https://kubernetes.io/docs/reference/glossary/?fundamental=true 標準用語集]
===インストール===
====[[Mac]]にインストール====
*https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/README.md
[https://www.typea.info/blog/index.php/2020/11/17/mac_microk8s_dashboard_etc/ ダッシュボード接続手順、トラブルシュート]
<pre>
$ microk8s enable dashboard dns
$ microk8s dashboard-proxy
</pre>
===[[Kubectl]]===
</pre>
==[https://github.com/kubernetes/examples Kubernetesサンプル]==
==Up and Deploy==
{{amazon|4873118409}}
*https://github.com/kubernetes-up-and-running/kuard
===クラスタ===
----
*https://kubernetes.io/ja/docs/tutorials/kubernetes-basics/
*Kubernetesクラスターは以下の2種類のリソースで構成
</pre>
==Up and Deploy==
{{amazon|4873118409}}
*https://github.com/kubernetes-up-and-running/kuard
===Pod===
====作成====
</pre>
====execでコマンド実行====
*[[kubectl]] -it で対話実行
<pre>
$ kubectl exec -it pod/nginx-pod -- /bin/sh
#
</pre>
====コンテナローカル間でファイルコピー====
*ローカル のファイルを、Podにコピー
*ストレージを管理することはインスタンスを管理することとは全くの別物
*PersistentVolumeサブシステムは、ストレージが何から提供されているか、どのように消費されているかをユーザーと管理者から抽象化するAPIを提供
*Podは、PersistentVolumeClaimを通して「こういうspecのVolumeが欲しい」と要求を出すと、その要求に一番近いPersistentVolumeがmountされるという仕組み*metadata.name、metadata.labelsと、spec.selector.matchLabels、spec.selector.matchExpressionsの値を合わせることで、PersistentVolumeとPersistentVolumeClaimのマッチングをより明示的に、期待したとおりにできる*https://thinkit.co.jp/article/14195
===PersistentVolume (PV)===
*ストレージクラスを使って管理者もしくは動的にプロビジョニングされるクラスターのストレージの一部
</pre>
====PersistentVolumeClaimsエラーの対応====
<pre>
$ kubectl describe pods
ubuntu@microk8s-vm:~$ sudo mkdir /mnt/data
</pre>
*[https://kubernetes.io/ja/docs/concepts/storage/persistent-volumes/ accessModes]**ReadWriteOnce –ボリュームは単一のNodeで読み取り/書き込みとしてマウントできます**ReadOnlyMany –ボリュームは多数のNodeで読み取り専用としてマウントできます**ReadWriteMany –ボリュームは多数のNodeで読み取り/書き込みとしてマウントできます<blockquote>HostPath は、ReadWriteOnce しか選択できない</blockquote>
<pre>
apiVersion: v1
</pre>
===順序付けられた Pod 生成===
*StatefulSet n レプリカのために、Pod がデプロイされるときシーケンシャルに生成され順序づけられる(0...n-1)
<pre>
$ kubectl get pods -w -l app=nginx
</pre>
===順序付けられた StatefulSetのpod===*StatefulSetに含まれるPodは、一意な順序と安定したネットワークIDを持つ*StetefulSetのPod は一意のIDを持つ*このIDは、一意の順序付けられたインデックス、それぞれのpodがStatefulSetコントローラに結び付けられている*Pod 生成の名前は、<statefulset名>-<順序づけれれたindex> となる。<pre>$ kubectl get pods -l app=nginxNAME READY STATUS RESTARTS AGEweb-1 0/1 Pending 0 22hweb-0 0/1 Unknown 0 23h</pre> ===Stable ネットワークIDを使用する ===*それぞれのPod は順序付けられたインデックスに基づく安定したホスト名を持つ*StatefulSet n レプリカのために、Pod がデプロイされるときシーケンシャルに生成され順序づけられるkubectl exec でそれぞれのpodにhostname コマンドを実行する <pre>$ for i in 0 1; do kubectl exec pod/web-$i hostname; donekubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.web-0kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.Error from server (BadRequest): pod web-1 does not have a host assignedAn error occurred when trying to execute 'sudo microk8s.kubectl exec pod/web-1 hostname' with 'multipass': returned exit code 1.</pre> <blockquote>永続化Volumeが、hostPath指定の場合、1つのPodからしか接続できないため立ち上がらない。</blockquote><pre>$ kubectl describe pods web-1 :Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 22h (x14 over 23h) default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.</pre>===[[Ubuntu NFS構成|NFS]]の構成===*[[Ubuntu NFS構成]]*[https://www.server-world.info/en/note?os=Ubuntu_20.04&p=microk8s&f=5 microk8s storage class]*[https://qiita.com/Esfahan/items/7ad7695ea78c7630239a 外部ストレージをマウント]*[https://qiita.com/Esfahan/items/68e2d97545091cb6d0ac NFS storage class] *https://thinkit.co.jp/article/14195*https://kubernetes.io/docs/concepts/storage/volumes/*https://github.com/kubernetes/examples/tree/master/staging/volumes/nfs [https://baremetal.jp/blog/2018/04/17/541/ NFS] <pre>apiVersion: v1kind: PersistentVolumemetadata: name: web-pv labels: type: localspec: capacity: storage: 5Gi accessModes: - ReadWriteMany storageClassName: slow nfs: server: 192.168.0.n47 path: "/var/nfs/general"</pre> <pre>$ kubectl describe pvName: web-1pvLabels: type=localAnnotations: <none>Finalizers: [kubernetes.io/pv-protection]StorageClass: slowStatus: AvailableClaim: Reclaim Policy: RetainAccess Modes: RWXVolumeMode: FilesystemCapacity: 5GiNode Affinity: <none>Message: Source: Type: NFS (an NFS mount that lasts the lifetime of a pod) Server: 192.168.0.47 Path: /var/nfs/general ReadOnly: falseEvents: <none></pre>
===Pods in a StatefulSet===https://qiita.com/silverbirder/items/d3522237b28703a9adb6<pre> Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 2s (x6 over 5m58s) default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.</pre>
==デプロイ==