k8s 创建pod和删除pod

1、查看所有pod

 [root@k8s1 ~]# kubectl get pods --all-namespaces

在这里插入图片描述
2、下载nginx镜像

https://hub.docker.com/_/nginx?tab=tags    ##浏览器打开

在这里插入图片描述
3、pull到docker仓库

[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台机器。

解释

  • nginx 别名
  • --image= 镜像PEPOSTIORY名称
[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资源的详细信息

  • kubectl describe pod [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

  • kubectl exec -it [pod名称] -n default bash
[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

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值