1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[K8s] マニフェストからポッドを起動

Last updated at Posted at 2020-10-05

概要

本投稿はminikubeを使用し、マニフェストからポッドのみを起動させる内容をまとめた個人メモです。
本番運用ではポッドのみを起動させることはないので要注意。

マニフェストについて

マニフェストとは、K8sのオブジェクトを生成するために、そのオブジェクトに対応するAPIバージョン、メタ情報、使用などをyamlやjsonで定義したファイルのことです。
今回はポッドのみを起動させる最小単位でオブジェクトの生成を行います。

マニフェストの適応

今回使用するマニフェストは以下の通りです。
ポッドで動かすコンテナとしてnginxの最新バージョンを使用します。

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:latest

マニフェスト定義後、以下コマンドを使用しデプロイを行います。

$ kubectl apply -f nginx-pod.yml
pod/nginx created

以下コマンドで状態を確認します。

$ kubectl get pod nginx -o wide
NAME      READY     STATUS    RESTARTS   AGE       IP           NODE       NOMINATED NODE
nginx     1/1       Running   0          2m        172.17.0.4   minikube   <none>

ポッドの疎通確認

表示されているIPアドレスはクラスタネットワークのノード間でのみ通信可能な内部のIPのため、ホストからアクセスすることはできません。

$ curl 172.17.0.4
curl: (7) Failed to connect to 172.17.0.4 port 80: Network is unreachable

ポッド間の通信を確認するため、busyboxコンテナを立ち上げ疎通確認を行います。
nginxに正常にアクセスできることが確認できます。

$ kubectl run busybox --image=busybox --restart=Never --rm -it sh
If you don't see a command prompt, try pressing enter.
/ # wget 172.17.0.4
Connecting to 172.17.0.4 (172.17.0.4:80)
saving to 'index.html'
index.html           100% |*****************************************************************************************************************************|   612  0:00:00 ETA
'index.html' saved
/ #
$ kubectl get pod -o wide
NAME      READY     STATUS    RESTARTS   AGE       IP           NODE       NOMINATED NODE
busybox   1/1       Running   0          1m        172.17.0.5   minikube   <none>
nginx     1/1       Running   0          15m       172.17.0.4   minikube   <none>

マニフェストで作成した環境はdeleteを使用し削除してください。

$ kubectl delete -f nginx-pod.yml

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?