LoginSignup
0
0

More than 5 years have passed since last update.

Kubernetes Workloadsリソース: Pod について

Posted at

「Kubernetes完全ガイド」 を元に、Workloadsリソースの動作確認を行った結果をまとめます。

実行環境

Kubernetes / kubectl version : 1.5.2
CentOS 7.4

構築手順1構築手順2

[root@master ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", 
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2"

Kubernetes Workloads リソース

コンテナの実行に関するリソース。Pod、ReplicationController、ReplicaSet、Deployment、DaemonSet、StatefulSet、Job、CronJobの8種類があり、それぞれの階層関係は以下の通り

image.png

出典:「Kubernetes完全ガイド」

Pod

Workloadsリソースの最小単位。1つ以上のコンテナから構成され、同じPod内のコンテナはIPアドレスを共有(ポート番号はサービス毎)

Podの定義用マニフェスト (ngixコンテナを1つ起動)

sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sample-pod
spec:
  containers:
    - name: nginx-container
      image: nginx:1.12

Podを作成

[root@master ~]# kubectl apply -f sample-pod.yaml
pod "sample-pod" created

Podを表示

[root@master ~]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
sample-pod      1/1       Running   0          42s

Pod内のサービス競合

  • nginx(80/tcp)とredis(6379/tcp)の2つのコンテナを持つPodの作成   → 成功
sample-2pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sample-2pod
spec:
  containers:
   - name: nginx-container
     image: nginx:1.12
   - name: redis-container
     image: redis:3.2
[root@master ~]# kubectl apply -f sample-2pod.yaml
pod "sample-2pod" created

[root@master ~]# kubectl get pods
NAME                                               READY     STATUS    RESTARTS   AGE
sample-2pod                                        2/2       Running   0          19s
  • nginx(80/tcp)コンテナを2つ起動するPodの作成 → 失敗
sample-2pod-fail.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sample-2pod-fail
spec:
  containers:
    - name: nginx-container-112
      image: nginx:1.12
    - name: nginx-container-113
      image: nginx:1.13

作成されるが、起動エラーに

[root@master ~]# kubectl apply -f sample-2pod-fail.yaml
pod "sample-2pod-fail" created

[root@master ~]# kubectl get pods
NAME                                               READY     STATUS    RESTARTS   AGE
sample-2pod                                        2/2       Running   0          14m
sample-2pod-fail                                   1/2       Error     2          27s

コンテナへのログイン(疑似端末の生成による)

[root@master ~]# kubectl exec -it sample-pod /bin/bash

コンテナ内でLISTENしているポートと、起動しているプロセスの確認

root@sample-pod:/# apt-get update && apt-get -y install iproute procps
Get:1 http://security-cdn.debian.org/debian-security stretch/updates InRelease [94.3 kB]

root@sample-pod:/# ss -napt | grep LISTEN
LISTEN     0      0            *:80                       *:*                   users:(("nginx",pid=1,fd=6))
root@sample-pod:/# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  32400  3208 ?        Ss   04:57   0:00 nginx:
nginx        5  0.0  0.0  32872  1576 ?        S    04:57   0:00 nginx:
root        11  0.0  0.1  18132  2008 ?        Ss   05:30   0:00 /bin/ba
root       371  0.0  0.0  36628  1584 ?        R+   05:32   0:00 ps aux
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