K8S对象 -静态Pod
目录
1. 概述
静态pod是由Node节点的kubelet进行管理的,仅存在于该Node节点上。它不能通过Master的API Server 进行管理。
2. 配置文件方式启动
2.1 创建
- 登陆Node服务器,将yml文件放到下边目录: /etc/kubernetes/manifests
- 创建文件 nginx.yml 如下:
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
app: static-web
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
说明:过一会而就可以启动,通过下边方式查看结果
2.2 查看
- 在node上用docker命令查看
过一会而可以看见启动了一个新容器
[root@DoN01 manifests]# docker ps |grep nginx
18196b6118f3 nginx "/docker-entrypoint.…" 25 seconds ago Up 24 seconds k8s_web_static-web-don01_default_d3099453cc54959f6d7739e600ec72c9_0
- 在master上查看
可以看到刚才那个node上启动了一个pod
[root@DoM01 yml]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
static-web-don01 1/1 Running 0 11m 10.244.3.28 don01 <none> <none>
2.3 删除
- 虽然能在master上查看,但是不能在master上删除。
- 在node节点上删除yml文件即会删除该pod
2.4 访问
虽然不能在master上控制但是可以在master上创建service访问
- 在master上编写yml文件如下
apiVersion: v1
kind: Service
metadata:
name: static-web
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30201
selector:
app: static-web
- 创建service
kubectl create -f service.yml
- 访问
3. 根据HTTP服务器伤文件创建静态Pod
说明:该方法 kubelet 将自动从页面上拉取yml文件创建静态pod
3.1 将yml文件放到web服务器上
如下,可以通过http访问:
3.2 修改配置文件
修改kubelet的启动参数,文件为: /var/lib/kubelet/kubeadm-flags.env
添加启动参数 --manifest-url=http://10.10.xxx.xxx:8088/nginx.yml 如下:
KUBELET_KUBEADM_ARGS="--cgroup-driver=cgroupfs --manifest-url=http://10.10.xxx.xxx:8088/nginx.yml --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.1"
3.3 重启kubelet
- 重启服务
# systemctl restart kubelet
- 查看kubelet如下
说明:最后一行可见 “Successfully read pods from URL”
[root@DoN01 manifests]# systemctl status kubelet
kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since 三 2021-02-03 20:31:11 CST; 30s ago
Docs: https://kubernetes.io/docs/
Main PID: 112569 (kubelet)
Tasks: 38
Memory: 42.8M
CGroup: /system.slice/kubelet.service
└─112569 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --...
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929669 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolume start...
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929709 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolu...c369ae")
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929790 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolume start...
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929816 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolu...c369ae")
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929836 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolume start...
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929852 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolu...8a7a50")
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929869 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolu...8a7a50")
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929906 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolume start...
2月 03 20:31:16 DoN01 kubelet[112569]: I0203 20:31:16.929965 112569 reconciler.go:203] operationExecutor.VerifyControllerAttachedVolu...8a7a50")
2月 03 20:31:31 DoN01 kubelet[112569]: I0203 20:31:31.176867 112569 http.go:75] Successfully read pods from URL.
3.4 查看结果
master上查看结果如下
[root@DoM01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
static-web-don01 1/1 Running 0 12m
3.5访问
访问方式同2.4