**1. 一个容器组成的Pod的 `pod01.yaml` 示例**
```yml
apiVersion: v1
kind: Pod
metadata:
name: mytomcat
labels:
name: mytomcat
spec:
containers:
- name: mytomcat
image: tomcat
ports:
- containerPort: 8000
```
**2. 多个容器组成的Pod的 `pod02.yaml` 示例**
```yml
apiVersion: v1
kind: Pod
metadata:
name: myweb
labels:
name: tomcat-redis
spec:
containers:
- name: tomcat
image: tomcat
ports:
- containerPort: 8000
- name: redis
image: redis
ports:
- containerPort: 6379
```
**3. 创建Pod**
语法:
```shell
kubectl create -f xxx.yaml
```
示例:
```shell
# kubectl create -f pod02.yaml
pod/myweb created
```
**4. 查看**
语法:
```shell
语法1:kubectl get pod <Pod_name>
语法2:kubectl get po <Pod_name>
语法3:kubectl get pod <Pod_name> -o wide
语法4:kubectl get po <Pod_name> -o wide
语法5:kubectl describe pod <Pod_name>
语法6:kubectl describe po <Pod_name>
```
示例:
```shell
(1)方式1
# kubectl get pod myweb
NAME READY STATUS RESTARTS AGE
myweb 0/2 ContainerCreating 0 99s
(2)方式2
# kubectl get po myweb
NAME READY STATUS RESTARTS AGE
myweb 0/2 ContainerCreating 0 113s
(3)方式3
# kubectl get pod myweb -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
myweb 0/2 ContainerCreating 0 2m56s <none> k8s-node-02 <none> <none>
(4)方式4
# kubectl describe pod myweb
Name: myweb
Namespace: default
Priority: 0
Node: k8s-node-02/192.168.1.13
Start Time: Thu, 17 Feb 2022 21:09:06 +0800
Labels: name=tomcat-redis
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Containers:
tomcat:
Container ID:
Image: tomcat
Image ID:
Port: 8000/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-br2cp (ro)
redis:
Container ID:
Image: redis
Image ID:
Port: 6379/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-br2cp (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-br2cp:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-br2cp
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned default/myweb to k8s-node-02
Normal Pulling 3m15s kubelet, k8s-node-02 Pulling image "tomcat"
```
**5. 删除**
语法:
```shell
语法1:kubectl delete -f pod <Pod_name>.yaml
语法2:kubectl delete pod --all
语法3:kubectl delete pod <Pod_name>
```
示例:
```shell
# kubectl delete -f pod myweb.yaml
# kubectl delete pod myweb
pod "myweb" deleted
```
- K8s是什么
- K8s特点
- K8s功能
- 为什么用容器
- K8s集群搭建
- 1. 集群架构
- 2. 机器初始化
- 3. 安装Docker
- 4. 配置k8s镜像仓库
- 5. 安装k8s核心工具
- 6. 初始化主节点
- 7. node节点加入集群
- 8. 安装Pod网络插件
- 9. 测试k8s集群
- yaml资源文件
- yaml文件作用
- yaml文件编辑语法
- 资源清单描述方法
- 命令行工具kubectl
- kubectl是什么
- kubectl命令语法
- Pod
- Pod是什么
- Pod特征
- Pod定义
- Pod基本操作
- Pod分类
- Pod生命周期
- Pod重启策略
- 镜像拉取策略
- 资源限制
- 健康检查
- Label
- Namespace
- ReplicationController
- ReplicaSet
- Deployment
- HorizontalPodAutoscaler
- Service
- Service是什么
- 应用Service
- Ingress
- Ingress是什么
- 部署ingress-nginx
- Helm
- Helm是什么
- Volume
- Volume是什么
- NFS的使用
- PV与PVC
- PV与PVC是什么
- PV与PVC的使用
- ConfigMap
- ConfigMap是什么
- ConfigMap创建
- ConfigMap使用
- ConfigMap热更新
- 滚动更新Pod
- Secret
- Secret作用
- Secret类型