単一の実行コンテナでポッドを作成する場合は、kubectl createコマンドを次のように使用できます。
$ kubectl create deployment --image nginx
hello-world
deployment.apps/hello-world created
hello-world
は、目的のデプロイメントの名前に置き換えてください。ポッドには、接頭辞としてデプロイメント名を使用した名前が付けられています。nginx
は、コンテナ・イメージに置き換えてください。
デプロイメント、ポッドおよびサービスの名前は、DNS-1123ラベルと一致する要件に従います。それらは、英数文字(小文字)または-
で構成されていて、先頭と末尾が英数文字になっていることが必要です。正規表現で名前を検証する場合は、'[a-z0-9]([-a-z0-9]*[a-z0-9])?
'を使用します。デプロイメントに無効な名前を使用すると、エラーが返されます。
Kubernetes内で新しいアプリケーションを実行する際に使用できる追加のオプション・パラメータは多数あります。たとえば、起動する必要のあるレプリカ・ポッドの数を実行時に指定することも、ポッドのコンポーネントを簡単に識別できるようにするためにデプロイメントにラベルを適用することもできます。使用可能なオプションの完全なリストは、kubectl run --helpを実行することで確認できます。
新しいアプリケーション・デプロイメントによって1つ以上のポッドが作成されたことを確認するには、次のようにkubectl get podsコマンドを使用します。
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-world-5f55779987-wd857 1/1 Running 0 1m
kubectl describeコマンドは、ポッドの詳細を表示するために使用します。この詳細では、実行中のコンテナ、基になったイメージ、現在ポッドをホストしているノードなどが示されます。
$ kubectl describe pods
Name: hello-world-5f55779987-wd857
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: worker1.example.com/192.0.2.11
Start Time: Fri, 16 Aug 2019 08:48:33 +0100
Labels: app=hello-world
pod-template-hash=5f55779987
Annotations: <none>
Status: Running
IP: 10.244.1.3
Controlled By: ReplicaSet/hello-world-5f55779987
Containers:
nginx:
Container ID: cri-o://417b4b59f7005eb4b1754a1627e01f957e931c0cf24f1780cd94fa9949be1d31
Image: nginx
Image ID: docker-pullable://nginx@sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe7...
Port: <none>
Host Port: <none>
State: Running
Started: Mon, 10 Dec 2018 08:25:25 -0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-s8wj4 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-s8wj4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-s8wj4
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
....