模板与帮助信息
# 获取 Pod 模板
[root@master ~]# kubectl run myweb --image=myos:nginx --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: myweb
name: myweb
spec:
containers:
- image: myos:nginx
name: myweb
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
# 获取资源对象模板
[root@master ~]# kubectl create namespace work --dry-run=client -o yaml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: work
spec: {}
status: {}
# 查询帮助信息
[root@master ~]# kubectl explain Pod.spec.restartPolicy
KIND: Pod
VERSION: v1
FIELD: restartPolicy <string>
DESCRIPTION:
Restart policy for all containers within the pod. One of Always, OnFailure,
Never. Default to Always. More info:
https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
Possible enum values:
- `"Always"`
- `"Never"`
- `"OnFailure"`
资源对象文件
[root@master ~]# mkdir app
[root@master ~]# cd app
[root@master app]# vim nginx.yaml
---
kind: Pod
apiVersion: v1
metadata:
name: nginx
spec:
containers:
- name: nginx
image: myos:nginx
[root@master app]# vim phpfpm.yaml
---
kind: Pod
apiVersion: v1
metadata:
name: php
spec:
containers:
- name: php
image: myos:php-fpm
管理资源对象
[root@master app]# ls
nginx.yaml phpfpm.yaml
# 使用资源对象文件创建应用
[root@master app]# kubectl apply -f nginx.yaml -f phpfpm.yaml
pod/nginx created
pod/php created
# 删除应用
[root@master app]# kubectl delete -f /root/app/
pod "nginx" deleted
pod "php" deleted
# 合并资源对象文件
[root@master app]# cat nginx.yaml >>app.yaml
[root@master app]# cat phpfpm.yaml >>app.yaml
# 创建资源对象
[root@master ~]# kubectl apply -f app.yaml
pod/nginx created
pod/php created
# 删除资源对象
<