Kubernetes 静态Pod

本文详细介绍了如何通过配置文件和HTTP方式创建和管理Kubernetes静态Pod,包括设置kubelet参数、静态Pod的yaml文件示例及删除策略。

静态Pod是由kubelet进行管理的仅存在特定的Node上的Pod。这些Pod不能通过API Server进行管理,也无法和RC、Deployment或者DaemonSet关联,并且不存在健康检查,该类型的Pod由kubelet创建的,并且只在kubelet所在的Node上运行。

创建静态Pod的方式有两种:

  • 配置文件
  • HTTP

一、配置文件

首先需要时设定kubelet启动参数“--podmainifest-path”,或者在kubelet的配置文件中设定staticPodPath,指定的路径是kubelet监控的路径(如果k8s集群由kubeadm搭建,那默认存储在目录/etc/kubernetes/manifests下),kubelet会定期检查该目录,并根据该目录下的yaml文件和json文件进行创建Pod操作。

例如:配置目录为/etc/kubelet.d,配置启动参数为--podmainifest-path=/etc/kubelet.d,然后重启kubelet。

在/etc/kubelet.d目录下放static_pod.yaml文件,内容如下:

---
apiVersion: v1
kind: Pod
metadata:
    name: static-pod
    labels:
        name: static-pod
spec:
    containers:
    - name: static-pod
      image: nginx
      ports:
      - name: web
        containerPort: 80

稍等片刻,便能够发现集群启动了一个pod(如长时间未启动,查看系统日志、var/log/messages)

$ kubectl get pods --all-namespaces
NAMESPACE     NAME                                           READY   STATUS    RESTARTS   AGE
default       static-pod-host-192-168-100-121                1/1     Running   0          8s

该pod无法使用API Server删除,如果尝试删除会使该pod处于pending状态,并且一直不会被删除。如果要删除该pod,只需要到之前存放yaml文件的目录下,删除相关的yaml文件即可

二、HTTP方式

同通过设定kubelet的启动参数‘--manifest-url’,kubelet将会定期从该URL地址下载Pod的定义文件,并以yanl或者json文件的格式进行解析,然后创建pod,实现方式和配置文件的方式一样

### Kubernetes Static Pod Documentation and Usage Static Pods are managed directly by the kubelet daemon on a specific node, without the need for the API server to manage them. These pods are always tied to the node where they reside and cannot be controlled via standard Kubernetes controllers like Deployments or ReplicaSets. To define a static pod, one must place its manifest file into a directory watched by the `kubelet`. By default, this is `/etc/kubernetes/manifests` on most systems[^4]. When the `kubelet` detects changes in any of these files (addition, modification, deletion), it will adjust the set of running containers accordingly. For example, consider creating a simple nginx static pod: ```yaml apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: nginx ``` Save this configuration as `/etc/kubernetes/manifests/nginx.yaml`, after which the `kubelet` service should automatically start an instance of the specified container on that particular machine. Unlike regular pods created through the API server, there's no direct way to interact with static pods using `kubectl apply` commands because they do not exist within etcd database nor have corresponding objects inside the cluster state maintained by apiserver. However, once started, users can still inspect logs, describe status, delete manually from filesystem level but all operations related specifically to managing lifecycle such as scaling up/down replicas aren't applicable here since those features rely heavily upon higher-level abstractions provided by other components outside just the local node itself.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值