Open6
k8s static podで消せないPodを作る
Static podをオンプレk8sで試す.
kubeadmはstatic pod manifestを置く場所が設定されている.
/etc/kubernetes/manifests as the path where kubelet should look for static Pod manifests. Names of static Pod manifests are:
etcd.yaml
kube-apiserver.yaml
kube-controller-manager.yaml
kube-scheduler.yaml
pod manifestを作成する
$ sudo vim /etc/kubernetes/manifests
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
role: myrole
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
static-web-xxx
ができる
% k get pods
NAME READY STATUS RESTARTS AGE
nginx-rbz55 1/1 Running 2 22d
nginx-vbj84 1/1 Running 1 17d
static-web-k8s1 1/1 Running 0 112m
masterに置かれる
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-rbz55 1/1 Running 2 22d 10.244.219.24 k8s3 <none> <none>
nginx-vbj84 1/1 Running 1 17d 10.244.219.25 k8s3 <none> <none>
static-web-k8s1 1/1 Running 0 115m 10.244.166.202 k8s1 <none> <none>
static pod manifestに,role2: yourrole
の変更を加えてみる
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
role: myrole
role2: yourrole
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
変更を検知してpodが作り直される
% k get po -w
NAME READY STATUS RESTARTS AGE
nginx-rbz55 1/1 Running 2 22d
nginx-vbj84 1/1 Running 1 17d
static-web-k8s1 0/1 Pending 0 0s
static-web-k8s1 0/1 Pending 0 0s
static-web-k8s1 1/1 Running 0 3s
稼働中のPodに変更を加えてみる
% kubectl edit po static-web-k8s
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Pod
metadata:
annotations:
....
labels:
role: myrole
role2: minerole
podは作り直されたが,roleはkubectl editで変更されたまま
% k describe po static-web-k8s1
Name: static-web-k8s1
Namespace: default
....
Labels: role=myrole
role2=minerole
Static Podを消すと再生成される
% k delete po static-web-k8s1
pod "static-web-k8s1" deleted
% k get po -w
NAME READY STATUS RESTARTS AGE
nginx-rbz55 1/1 Running 2 22d
nginx-vbj84 1/1 Running 1 17d
static-web-k8s1 0/1 Pending 0 2s
static-web-k8s1 1/1 Running 1 3s
起動したPodはpod manifestの通り生成される.削除直前までの変更は復元されない.
% k describe po static-web-k8s1
Name: static-web-k8s1
Namespace: default
...
Labels: role=myrole
role2=yourrole