Kubernetes 入门
Frank Heilmann
Platform Architect and Freelance Instructor
kubectl:与 Kubernetes 对象交互的主命令pod、service 等$$
常用模式:
kubectl create -f <Manifest.yml>:创建新对象,-f 表示"文件名"kubectl apply -f <Manifest.yml>:创建新对象并变更对象状态kubectl get <object>:
查看已部署对象概览kubectl describe <object>:查看对象详细信息$$
可通过命令行选项 --help 获取详细帮助
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25.4
ports:
- containerPort: 80
无状态应用:
中断后会重建新副本并继续运行。
apiVersion 和 kindmetadata 和 specspec 定义 replicas 数量、selector 和 templateselector 稍后介绍template 描述在 Deployment 中创建 Pod 的细节apiVersion: apps/v1
kind: Deployment
metadata:
name: <deployment name>
labels:
app: <a label for the application>
spec:
replicas: <number of initial replicas>
selector:
matchLabels:
app: <matches the label above>
template:
metadata:
labels:
app: <label to be given to each pod>
spec:
containers:
- name: <container name>
image: <the image to be used>
ports:
- containerPort: <ports for networking>
kubectl apply -f <manifest.yml> 创建 Pod 并应用变更。Kubernetes 入门