1.1 POD
1.1.1 创建一个pod
定义一个pod (分层使用两个空格,勿用tab键)
# vim nginx.yaml apiVersion: v1 # 必选, API 的版本号 kind: Pod # 必选,类型 Pod metadata: # 必选,元数据 name: nginx # 必选,符合 RFC 1035 规范的 Pod 名称 spec: # 必选,用于定义 Pod 的详细信息 containers: # 必选,容器列表 - name: nginx # 必选,符合 RFC 1035 规范的容器名称 image: nginx:1.15.12 # 必选,容器所用的镜像的地址 ports: # 可选,容器需要暴露的端口号列表 - containerPort: 80 # 端口号
创建pod
# kubectl create -f nginx.yaml pod/nginx created
查看pod状态
# kubectl get po ### 使用 po 或者 pod 都可以 NAME READY STATUS RESTARTS AGE nginx 1/1 Running 0 47s
使用kubectl run 创建一个pod
[root@k8s-master03 ~]# kubectl run nginx-run --image=nginx:1.15.12 pod/nginx-run created
##使用--dry-run 创建
[root@k8s-master03 ~]# kubectl run nginx --image=nginx:1.15.12 -oyaml --dry-run > pod.yaml
W1217 17:17:26.985672 75520 helpers.go:622] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@k8s-master03 ~]#
[root@k8s-master03 ~]# cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx:1.15.12
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
删除pod
[root@k8s-master03 ~]# kubectl delete -f nginx.yaml ##method1 指定yaml删除 pod "nginx" deleted [root@k8s-master03 ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-run 1/1 Running 0 93s [root@k8s-master03 ~]# kubectl delete po nginx-run ##method2 指定pod NAME删除 pod "nginx-run" deleted [root@k8s-master03 ~]# kubectl get po No resources found in default namespace.
查看pod的所有资源信息
[root@k8s-master03 ~]# kubectl api-resources NAME SHORTNAMES APIVERSION NAMESPACED KIND bindings v1 true Binding componentstatuses cs v1 false ComponentStatus configmaps cm v1 true ConfigMap endpoints ep v1 true Endpoints events ev v1 true Event limitranges limits v1 true LimitRange namespaces ns v1 false Namespace nodes no v1 false Node persistentvolumeclaims pvc v1 true PersistentVolumeClaim persistentvolumes pv v1 false PersistentVolume pods po v1 true Pod podtemplates v1 true PodTemplate replicationcontrollers rc v1 true ReplicationController resourcequotas quota v1 true ResourceQuota secrets v1 true Secret serviceaccounts sa v1 true ServiceAccount services svc v1 true Service mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration ................
标签:kubectl,run,v1,基础,nginx,POD,K8S,true,pod From: https://www.cnblogs.com/zhongyuping/p/16989279.html