| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
8,969 バイト追加 、 2021年2月16日 (火) 11:28
*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]]にインストール====
</pre>
*Driverを[[VirtualBox]]に変更する場合、先に変更してから、install
*[https://www.typea.info/blog/index.php/2020/11/20/mac_multipass_microk8s_virtuabox_networibridge/ Virtual Boxでネットワークブリッジを作成する]
<pre>
$ microk8s install
</pre>
 
====[[Ubuntu]]にインストール====
<pre>
|-
|}
 
===マニフェスト===
*[https://kubernetes.io/ja/docs/reference/ リファレンス]
*[https://kubernetes.io/docs/reference/using-api/api-overview/ API概要]
*[https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/ リファレンス v1.19]
===ダッシュボード===
*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>
====PersistentVolume生成====
*hostPath hostPath PersistentVolume を作成する。KubernetesはhostPathをシングルノードクラスタの開発/テストでサポートする*hostPath hostPath PersistentVolume は、ネットワークアタッチドストレージをエミュレートしたものとしてNodeのファイル、もしくはディレクトリを使用する*製品版のクラスタでは、hostPathを使わない方が良い。クラスター管理者は、その代わりにネットワークリソース、Google 製品版のクラスタでは、hostPathを使わない方が良い。クラスター管理者は、その代わりにネットワークリソース、Google Compute Engine 永続ディスクや、NFS 共有、Amazon Elastic Block Store Volumeを準備する
*クラスター管理者は動的プロビジョニングのために、StorageClassを利用する
<pre>
hostPath:
path: "/mnt/data"
</pre>
 
<pre>
$ kubectl apply -f https://k8s.io/examples/pods/storage/pv-volume.yaml
persistentvolume/task-pv-volume created
</pre>
 
<pre>
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 10Gi RWO Retain Available manual 41s
</pre>
====PersistentVolumeClaimの生成====
*PodはPersistentVolumeClaimを物理ストレージの要求に使用する
<pre>
$ kubectl apply -f https://k8s.io/examples/pods/storage/pv-claim.yaml
persistentvolumeclaim/task-pv-claim created
</pre>
 
<pre>
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
task-pv-volume 10Gi RWO Retain Bound default/task-pv-claim manual 44m
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
task-pv-claim Bound task-pv-volume 10Gi RWO manual 77s
</pre>
====Podの生成====
*PersistentVolumeClaimをVolumeとして利用するPodの作成
 
<pre>
apiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
</pre>
<pre>
$ kubectl apply -f https://k8s.io/examples/pods/storage/pv-pod.yaml
pod/task-pv-pod created
</pre>
 
<pre>
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
task-pv-pod 1/1 Running 0 2m5s
</pre>
*マウントしたVolume情報を確認
<pre>
kubectl exec -it pod/task-pv-pod -- /bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
# cat /usr/share/nginx/html/index.html
Hello from Kubernetes storage
</pre>
 
 
<pre>
# apt update
# apt install curl
# curl http://localhost
Hello from Kubernetes storage
</pre>
====クリーンアップ====
<pre>
$ kubectl delete pod task-pv-pod
$ kubectl delete pvc task-pv-claim
$ kubectl delete pv task-pv-volume
</pre>
*https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/web/web.yaml
*ダウンロードしてapply
 
<pre>
$ kubectl apply -f ./files/statefulset-basic/web.yaml
</pre>
===Ordered =PersistentVolumeClaimsエラーの対応====<pre>$ kubectl describe podsName: web-0 :Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 40s (x8 over 9m33s) default-scheduler 0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.</pre> *https://qiita.com/silverbirder/items/d3522237b28703a9adb6*https://stackoverflow.com/questions/52668938/pod-has-unbound-persistentvolumeclaims <pre>$ multipass sh microk8s-vmubuntu@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: v1kind: PersistentVolumemetadata: name: web-pv labels: type: localspec: capacity: storage: 5Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data"</pre> <pre>$ microk8s apply -f ./files/statefulset-basic/pv.yaml persistentvolume/web-pv created</pre> ===順序付けられた Pod Creation生成===For a *StatefulSet with n replicas, when Pods are being deployed, they are created sequentially, ordered from {レプリカのために、Pod がデプロイされるときシーケンシャルに生成され順序づけられる(0...n-1}. Examine the output of the )<pre>$ kubectl get pods -w -l app=nginxNAME READY STATUS RESTARTS AGEweb-0 0/1 Pending 0 7m32sweb-0 0/1 Pending 0 20mweb-0 0/1 ContainerCreating 0 20mweb-0 0/1 ContainerCreating 0 20mweb-0 1/1 Running 0 20mweb-1 0/1 Pending 0 0sweb-1 0/1 Pending 0 0s</pre> ===StatefulSetのpod===*StatefulSetに含まれるPodは、一意な順序と安定したネットワークIDを持つ*StetefulSetのPod は一意のIDを持つ*このIDは、一意の順序付けられたインデックス、それぞれのpodがStatefulSetコントローラに結び付けられている*Pod の名前は、<statefulset名>-<順序づけれれたindex> となる。<pre>$ kubectl get command pods -l app=nginxNAME READY STATUS RESTARTS AGEweb-1 0/1 Pending 0 22hweb-0 0/1 Unknown 0 23h</pre> ===Stable ネットワークIDを使用する ===*それぞれの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 the first terminala future version. Use kubectl exec [POD] -- [COMMAND] instead. Eventually, the output web-0kubectl exec [POD] [COMMAND] is DEPRECATED and will look like 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.47 path: "/var/nfs/general"</pre>  <pre>$ kubectl describe pvName: web-pvLabels: type=localAnnotations: &lt;none&gt;Finalizers: [kubernetes.io/pv-protection]StorageClass: slowStatus: AvailableClaim: Reclaim Policy: RetainAccess Modes: RWXVolumeMode: FilesystemCapacity: 5GiNode Affinity: &lt;none&gt;Message: Source: Type: NFS (an NFS mount that lasts the example belowlifetime of a pod) Server: 192.168.0.47 Path: /var/nfs/general ReadOnly: falseEvents: &lt;none&gt;</pre>  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>
==デプロイ==

案内メニュー