云原生之kubectl命令详解(二)及pod的相关操作

本文详细介绍了kubectl命令在云原生环境中的应用,包括查看Pod详细信息、跨主机登录容器、删除和管理Pod,以及Pod的生命周期。通过实例展示了如何扩容和缩容副本集,以及操作Service的各种类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、kubectl命令详解

1、查看某个资源的详细信息:kubectl describe pod pod_name -n nameapace

2、查看指定命名空间中pod的基本信息:kubectl get pods -n namespace

3、跨主机登录容器:kubectl exec -it pod_name /bin/bash -n namespace

4、删除pod

4.1、直接删除pod。但是deployment,副本控制器还在,他就会自己再创建一个。

①、直接删除POD 

②、查看,发现与原先pod_name不一样,

 4.2、删除pod副本控制器deployment:

4.3、如果删除过程中出现幺蛾子,Pod无法删除,总是处于terminating状态,则执行强行删除--force --grace-period=0

5、命令行扩容和缩容

5.1、副本集的扩容

①查看原有副本集:1个 

②扩容副本集为4

5.2、副本集的缩容 

6、删除service

7、查看pod网络状态详情信息和service暴露的端口

8、查看关联后的节点

9、查看service的描述信息

二、pod的生命周期

1、创建一个Pod,启动nginx实例,暴露容器80端口,设置副本集为3(创建pod)

namespace为默认

2、 发布:kubectl expose命令 ​编辑

3、 查看端口

​三、 service的type类型


一、kubectl命令详解

1、查看某个资源的详细信息:kubectl describe pod pod_name -n nameapace(不加-n namespace 默认为查看default命名空间资源)

[root@master ~]# kubectl describe pods -n kube-public         

                                                            ### 查看指定命名空间中的pod的详细信息

                            ### 在处理故障时,常使用此命令查看pod 的events信息来定位问题                                          

Name:         nginx-w1-7464d66457-psk6h
Namespace:    kube-public
Priority:     0
Node:         node01/192.168.159.11
Start Time:   Wed, 02 Nov 2022 01:40:47 +0800
Labels:       app=nginx-w1
              pod-template-hash=7464d66457
Annotations:  <none>
Status:       Running
IP:           10.150.1.3
IPs:
  IP:           10.150.1.3
Controlled By:  ReplicaSet/nginx-w1-7464d66457
Containers:
  nginx:
    Container ID:   docker://4011df060a9ad777793f061675fc1a784f4effe56f5585d91d5ba3670660c620
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:943c25b4b66b332184d5ba6bb18234273551593016c0e0ae906bab111548239f
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Wed, 02 Nov 2022 01:41:06 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-llzgh (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-llzgh:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
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>


Name:         nginx-x1-77484d895f-ddhqt
Namespace:    kube-public
Priority:     0
Node:         node02/192.168.159.13
Start Time:   Thu, 03 Nov 2022 16:16:11 +0800
Labels:       app=nginx-x1
              pod-template-hash=77484d895f
Annotations:  <none>
Status:       Running
IP:           10.150.2.3
IPs:
  IP:           10.150.2.3
Controlled By:  ReplicaSet/nginx-x1-77484d895f
Containers:
  nginx:
    Container ID:   docker://ecc07803682f2d7a51037024354dae0d190841443121ca0a8514ab224179cbf5
    Image:          nginx:latest
    Image ID:       docker-pullable://nginx@sha256:943c25b4b66b332184d5ba6bb18234273551593016c0e0ae906bab111548239f
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 03 Nov 2022 16:16:36 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-47hxr (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-47hxr:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值