1、查看所有pod
[root@k8s1 ~]# kubectl get pods --all-namespaces
https://hub.docker.com/_/nginx?tab=tags ##浏览器打开
[root@k8s1 ~]#docker pull nginx:stable-perl
[root@k8s1 ~]# docker images ##确认镜像已经在列表中
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx stable-perl 9e5f6711d527 3 days ago 178MB
4、创建Pod --直接在master节点上运行一个镜像,并且启动2台机器。
解释
[root@k8s1 ~]# kubectl run my-grafana-699cc7d885-42rxb --image=nginx --replicas=2 --port=80
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/my-nginx created
[root@localhost ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-grafana-699cc7d885-42rxb 1/1 Running 1 2d23h
这里需要等待一定的时间,容器的状态由ContainerCreating变为Running。
5、显示Pod资源的详细信息
Name: my-grafana-699cc7d885-42rxb
Namespace: default
Priority: 0
Node: 192.168.0.190/192.168.0.190
Start Time: Fri, 22 Jan 2021 18:31:38 +0800
Labels: app.kubernetes.io/instance=my-grafana
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=grafana
helm.sh/chart=grafana-0.0.2
pod-template-hash=699cc7d885
Annotations: checksum/config: c617987bca528039579ead83ffa6df149c1d040b3922ca1eb88a0760675323bf
checksum/dashboard-provider: 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
podpreset.admission.kubernetes.io/podpreset-timezone: 276
Status: Running
IP: 172.17.78.11
IPs:
IP: 172.17.78.11
Controlled By: ReplicaSet/my-grafana-699cc7d885
Containers:
grafana:
Container ID: docker://c1630f449ea7e28978edfbc599be0baaec3f39726afaa95db6f2a8a2f6d5517a
Image: registry.cn-chengdu.aliyuncs.com/set/k8s/grafana:helm_v1.0
Image ID: docker-pullable://registry.cn-chengdu.aliyuncs.com/set/k8s/grafana@sha256:38b9f6fc4dec7c6d7b773c5898ff6db5537d1c95ca6de12ebcc8a779cdc4c5b7
Port: 3000/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 25 Jan 2021 14:22:25 +0800
Last State: Terminated
Reason: Error
Exit Code: 255
Started: Fri, 22 Jan 2021 18:33:17 +0800
Finished: Mon, 25 Jan 2021 14:22:08 +0800
Ready: True
Restart Count: 1
Liveness: http-get http://:dashboard/ delay=120s timeout=5s period=10s #success=1 #failure=6
Readiness: http-get http://:dashboard/ delay=30s timeout=5s period=10s #success=1 #failure=6
Environment Variables from:
my-grafana-envvars ConfigMap Optional: false
my-grafana-secret Secret Optional: false
Environment:
TZ: Asia/Shanghai
Mounts:
/opt/bitnami/grafana/data from data (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-4kg6q (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
data:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: my-grafana
ReadOnly: false
default-token-4kg6q:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-4kg6q
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>
6、进入Pod
[root@localhost ~]# kubectl exec -it my-grafana-699cc7d885-42rxb -n default bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
I have no name!@my-grafana-699cc7d885-42rxb:/opt/bitnami/grafana$
cat /etc/issue
exit 退出
7、删除pod,需退出pod或者再开一个终端
kubectl delete pod [pod名称]
[root@localhost ~]# kubectl delete pod my-grafana-699cc7d885-42rxb
==========================================================
参考链接
https://blog.csdn.net/qq_41489540/article/details/114221388
删除了deployment之后 pod 也会被删除
8、删除pod,需退出pod或者再开一个终端
kubectl delete deployment [pod名称]`vbnet
[root@localhost ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
my-grafana 1/1 1 1 2d23h
my-nfs-client-nfs-client-provisioner 1/1 1 1 2d23h
my-prometheus-alertmanager 1/1 1 1 2d23h
my-prometheus-kube-state-metrics 1/1 1 1 2d23h
my-prometheus-pushgateway 1/1 1 1 2d23h
my-prometheus-server 1/1 1 1 2d23h
nginx 1/1 1 1 3m30s
[root@localhost ~]# kubectl delete deployment nginx