kubernetes(K8S)学习(五):K8S进阶(Lifecycle......偏理论)

一、Pod进阶学习之路

1.1 Lifecycle

官网https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

  • 挂起(Pending): Pod 已被 Kubernetes 系统接受,但有一个或者多个容器镜像尚未创建。等待时间包括调度 Pod 的时间和通过网络下载镜像的时间,这可能需要花点时间。
  • 运行中(Running): 该 Pod 已经绑定到了一个节点上,Pod 中所有的容器都已被创建。至少有一个容器正在运行,或者正处于启动或重启状态。
  • 成功(Succeeded): Pod 中的所有容器都被成功终止,并且不会再重启。
  • 失败(Failed): Pod 中的所有容器都已终止了,并且至少有一个容器是因为失败终止。也就是说,容器以非0状态退出或者被系统终止。
  • 未知(Unknown): 因为某些原因无法取得 Pod 的状态,通常是因为与 Pod 所在主机通信失败。

1.2 重启策略

官网https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
 
PodSpec有一个restartPolicy字段,可能值为Always、OnFailure、Never,缺省值为Always。restartPolicy应用于Pod中的所有容器。restartPolicy仅指kubelet在同一节点上重启容器。kubelet重新启动的退出容器以指数级的回退延迟(10s、20s、40s……)重新启动,上限为5分钟,并在成功执行10分钟后重新启动。正如Pods文档中所讨论的,一旦绑定到一个节点,一个Pod将永远不会被rebound(反弹)到另一个节点。

  • Always:容器失效时,即重启
  • OnFailure:容器终止运行且退出码不为0时重启
  • Never:永远不重启

1.3 静态Pod

静态Pod是由kubelet进行管理的,并且存在于特定的Node上。

不能通过API Server进行管理,无法与ReplicationController,Ddeployment或者DaemonSet进行关联,也无法进行健康检查。


1.4 健康检查

官网https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes

The kubelet can optionally perform and react to three kinds of probes on running Containers:
kubelet可以在运行的容器上选择性地执行和响应三种探针:

  • livenessProbe: Indicates whether the Container is running. If the liveness probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a liveness probe, the default state is Success.
  • readinessProbe: Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod’s IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure. If a Container does not provide a readiness probe, the default state is Success.
  • startupProbe: Indicates whether the application within the Container is started. All other probes are disabled if a startup probe is provided, until it succeeds. If the startup probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a startup probe, the default state is Success.

LivenessProbe探针:判断容器是否存活

ReadinessProbe探针:判断容器是否启动完成


1.5 ConfigMap

官网https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
 
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. (ConfigMaps允许您将配置工件与图像内容解耦,以保持容器化的应用程序的可移植性。)
 

说白了就是用来保存配置数据的键值对,也可以保存单个属性,也可以保存配置文件。
 
所有的配置内容都存储在etcd中,创建的数据可以供Pod使用。


1.5.1 命令行创建
<pre data-index="0" class="set-code-show prettyprint"><code class="prism language-shell has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;"><span class="token comment"># 创建一个名称为my-config的ConfigMap,key值时db.port,value值是'3306'</span>
kubectl create configmap my-config --from-literal<span class="token operator">=</span>db.port<span class="token operator">=</span><span class="token string">'3306'</span>
kubectl get configmap
<div class="hljs-button {2}" data-title="复制"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 

详情信息

apiVersion: v1
data:
db.port: "3306"
kind: ConfigMap
metadata:
creationTimestamp: "2019-11-22T09:50:17Z"
name: my-config
namespace: default
resourceVersion: "691934"
selfLink: /api/v1/namespaces/default/configmaps/my-config
uid: 7d4f338b-0d0d-11ea-bb46-00163e0edcbd

  
  
  

查看命令:kubectl get configmap myconfig -o yaml


1.5.2 从配置文件中创建

创建一个文件,名称为app.properties

内容:

name=jack
age=17

命令:

kubectl create configmap app --from-file=./app.properties
kubectl get configmap
kubectl get configmap app -o yaml

1.5.3 从目录中创建
mkdir config
cd config
mkdir a
mkdir b
cd ..

命令:

kubectl create configmap config --from-file=config/
kubectl get configmap

1.5.4 通过yaml文件创建

创建configmaps.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  special.how: very
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: env-config
  namespace: default
data
### Kubernetes 学习课程思维导图 以下是基于已有资料构建的 Kubernetes (k8s) 学习路径及其对应的思维导图框架。此框架涵盖了从基础知识到高级实践的核心主题,适合希望深入掌握 Kubernetes 技术的学习者。 --- #### 1. **入门与基础** - **Kubernetes 概述** - 容器编排的概念 - Kubernetes 的历史与发展背景[^1] - 主要组件介绍(Master Node, Worker Node) - **环境搭建** - Minikube 的安装与使用 - Kind/Kubeadm 集群初始化流程[^2] #### 2. **核心概念理解** - **基本资源对象** - Pod 设计原理及生命周期管理[^2] - Service 类型解析(ClusterIP, NodePort, LoadBalancer) - Ingress 控制器的作用与配置方法 - **YAML 文件编写技巧** - 对象字段含义详解 - 参数最佳实践示例 #### 3. **进阶技能提升** - **调度策略定制** - Taints & Tolerations 功能应用案例分析 - Affinity/Anti-affinity 设置逻辑解释 - **存储解决方案选型** - PersistentVolume(PV), PersistentVolumeClaim(PVC) 关系梳理 - CSI 插件生态现状简介 #### 4. **运维能力强化** - **监控体系建立** - Prometheus + Grafana 整合方案分享 - Custom Metrics Server 数据采集要点提示 - **日志收集处理** - Fluentd/Elasticsearch/Kibana(ELK Stack) 架构优势探讨 - Loki 替代传统 ELK 方案的优势对比 #### 5. **专项领域探索** - **CI/CD 流程对接** - Jenkins X/GitLab Runner 等工具链集成指南 - ArgoCD FluxCD DevOps 工具特性比较表 - **安全性加固措施** - Role-Based Access Control(RBAC) 授权机制讲解 - Network Policies 实施细节讨论 --- ### 思维导图样例结构 ```plaintext Kubernetes Learning Pathway ├── Introduction and Basics │ ├── Overview of Kubernetes │ │ └── History and Development Background [^1] │ ├── Environment Setup │ ├── Installation with Minikube / Kind / Kubeadm [^2] ├── Core Concepts Understanding │ ├── Basic Resource Objects │ │ ├── Pod Lifecycle Management [^2] │ │ ├── Types of Services │ │ └── Configuration via YAML Files │ └── Advanced Scheduling Strategies └── Operations Enhancement ├── Monitoring System Construction │ ├── Integration Solutions Using Prometheus + Grafana │ └── Usage Scenarios For Custom Metric Servers └── Log Collection Processing Methods And Tools Comparison ``` 以上仅为简化版示意,请根据个人需求进一步细化分支节点内容。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

꯭ 瞎꯭扯꯭蛋꯭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值