示例
# 创建
[rancher@master1 test]$ kubectl create -f pod.yml
pod/myapp-pod created
# 查询
[rancher@master1 test]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE
myapp-pod 1/1 Running 0 8s
# 查询json
[rancher@master1 test]$ kubectl get pod -n demo myapp-pod -o json |less
# 查询详细
[rancher@master1 test]$kubectl describe pod -n demo myapp-pod
# 获取被创建时的yml文件内容
[rancher@master1 test]$ kubectl get pod -n demo myapp-pod -o yaml
# 删除
[rancher@master1 test]$ kubectl delete -f .
pod "myapp-pod" deleted
# 创建和更新,apply大法好
[rancher@master1 test]$ kubectl apply -f .
pod/myapp-pod created
# edit更新,如果只更新标签,那么元数据里的标签不会更新,,所以一般不用这种方法,除非要改全改了
[rancher@master1 test]$ kubectl edit pod -n demo myapp-pod
# patch替换,比较麻烦,效果跟edit一样
[rancher@master1 test]$ kubectl patch pod -p '{"metadata":{"labels":{"app":"pod-nginx"}}}' myapp-pod -n demo
pod/myapp-pod patched
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
namespace: demo
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
- name: myapp-nginx
image: nginx