0
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 1 year has passed since last update.

k8s の実験(その3:pod の作成・削除)

Last updated at Posted at 2023-02-26

k8s の実験(その2:環境構築2)のつづき。

Docker では、コンテナを作成するコマンドは、以下のようでした。

$ docker run myweberser --image=nginx

k8s では、以下のようなコマンドになります。

$ kubectl run mywebserver --image=nginx
pod/mywebserver created

コンテナのことを、pod というみたいですね。
pod の存在を確かめてみます。

$ kubectl get pods
NAME          READY   STATUS    RESTARTS   AGE
mywebserver   1/1     Running   0          90s

では、pod の中に入るのは、どうしたらよいのでしょうか。

Docker では、以下のようでした。

$ docker exec -it mywebserver bash

k8s では、以下のようになります。

$ kubectl exec -it mywebserver -- bash
/#
/# exit

以下のコマンドを実行するとどうなるでしょうか。

$ kubectl exec -it mywebserver -- ls -l /
total 80
drwxr-xr-x   2 root root 4096 Feb  8 13:00 bin
drwxr-xr-x   2 root root 4096 Dec  9 19:15 boot
drwxr-xr-x   5 root root  360 Feb 26 12:19 dev
drwxr-xr-x   1 root root 4096 Feb  9 04:36 docker-entrypoint.d
-rwxrwxr-x   1 root root 1616 Feb  9 04:36 docker-entrypoint.sh
drwxr-xr-x   1 root root 4096 Feb 26 12:19 etc
drwxr-xr-x   2 root root 4096 Dec  9 19:15 home
drwxr-xr-x   1 root root 4096 Feb  8 13:00 lib
drwxr-xr-x   2 root root 4096 Feb  8 13:00 lib64
drwxr-xr-x   2 root root 4096 Feb  8 13:00 media
drwxr-xr-x   2 root root 4096 Feb  8 13:00 mnt
drwxr-xr-x   2 root root 4096 Feb  8 13:00 opt
dr-xr-xr-x 171 root root    0 Feb 26 12:19 proc
drwx------   1 root root 4096 Feb 26 12:25 root
drwxr-xr-x   1 root root 4096 Feb 26 12:19 run
drwxr-xr-x   2 root root 4096 Feb  8 13:00 sbin
drwxr-xr-x   2 root root 4096 Feb  8 13:00 srv
dr-xr-xr-x  13 root root    0 Feb 26 12:19 sys
drwxrwxrwt   1 root root 4096 Feb  9 04:36 tmp
drwxr-xr-x   1 root root 4096 Feb  8 13:00 usr
drwxr-xr-x   1 root root 4096 Feb  8 13:00 var

では、pod の削除はどうやってやるのでしょうか。

Docker では、以下のようでした。

$ docker stop mywebserver
$ docker rm mywebserver

k8s では、以下のようになります。
一度、pod の存在を確認してから、削除してみます。

$ kubectl get pods
NAME          READY   STATUS    RESTARTS   AGE
mywebserver   1/1     Running   0          11m
$ kubectl delete pod mywebserver 
pod "mywebserver" deleted
$ kubectl get pods
No resources found in default namespace.

上記のとおり、Docker では、一度コンテナを停止する必要がありますが、k8s では、pod が走っていても、削除することが出来ます。

K8S の実験(その4:node pool のアップグレード)につづく。

0
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
0
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?