创建Pod
#创建pod的yml文件
vim examplepod.yml
#内容:
apiVersiapiVon:v1
kind:Pod
metadata:
name:examplepod
spec:
containers:
- name: examplepod-container
image: busybox
imagePullPolicy: IfNotPresent
command: ['sh','-c']
args: ['echo "hello world!";sleep 3600']
------------------------------------------------------------
参数含义:
apiVersiapiVon:表示使用的API版本
kind:表示要创建的资源对象
metadata:表示该资源对象的元数据。name表示当前资源的名称
spec: 表示该资源对象的具体设置
containers: 表示容器的集合
name: 要创建的容器名称
image: 容器的镜像地址
imagePullPolicy: 镜像的下载策略:
Always:不管镜像是否存在都会进行一次拉取
Never: 不管镜像是否存在都不会拉取
IfNotPresent:只有镜像不存在时,才会进行拉取
command: 容器的启动命令列表
args: 启动参数列表
#创建Pod
kubectl apply -f examplepod.yml
查询Pod
#查询当前运行的所有Pod
kubectl get pods #(默认命名空间为default)
kubectl get pods -n <namespace>

kubectl get pods -A #(所有命名空间)

#查询指定Pod
kubectl get pods [Pod名称]
#持续监控
kubectl get pods [Pod名称] -w
#查看Pod的改要信息
kubectl get pods -o wide

#查看Pod的详情
kubectl describe pods [Pod名称]

#查看Pod的日志
kubectl logs [Pod名称]

修改Pod
kubectl replace -f [pod模板]
kubectl replace -f [pod模板] --force #强制,相当于重建Pod
删除Pod
kubectl delete pods [Pod名称] #删除单个Pod
kubectl delete -f [模板文件] #删除模板文件中的Pod
查看Pod配置
kubectl get pods [Pod名称] -o yaml
kubectl get pods [Pod名称] -o json
