跳到主要内容

认识

2024年08月28日
柏拉文
越努力,越幸运

一、认识


Kubernetes PodKubernetes 中最小的可部署计算单元,是一组一个或多个容器的集合,这些容器共享网络、存储资源,并作为一个整体进行管理。Pod 通常运行在 Kubernetes 集群中的一个节点上,并且每个 Pod 内的容器可以通过 localhost 相互通信。

二、语法


Kubernetes Pod 配置文件定义了 Pod 的各个方面,包括元数据、容器规范、卷、网络配置、探针、资源限制等。以下是一个 my-kubernetes-pod.yaml 配置文件中最常见和最全的指令的详解,涵盖了几乎所有可以配置的选项。

apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: default
labels:
app: my-app
annotations:
annotation-key: annotation-value
finalizers:
- kubernetes
ownerReferences:
- apiVersion: apps/v1
kind: ReplicaSet
name: my-replicaset
uid: 12345678-1234-1234-1234-123456789012

spec:
containers:
- name: my-container
image: nginx:1.19.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
env:
- name: ENV_VAR
value: "production"
- name: ENV_VAR_FROM_CONFIG
valueFrom:
configMapKeyRef:
name: my-config
key: config-key
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
volumeMounts:
- mountPath: /usr/share/nginx/html
name: web-content