当前位置:首页 > PAAS > 正文内容

K8S基本命令

poppy-jun3个月前 (12-04)PAAS97

注: 这里的C# 代码都是虚拟机中的命令

这里我就讲六个。

# kubectl run:在集群中使用指定镜像启动容器

# kubectl  get pods: 查看所有 Pod 列表

[root@master ~]# kubectl run nginx --image=192.168.200.23/library/nginx:1.14
pod/nginx created
[root@master ~]# kubectl get pods
NAME    READY   STATUS             RESTARTS   AGE
nginx   1/1     Running            0          10s

看到 status是runing就是成功了

# kubectl get nodes查看所有的nodes列表

# kubectl get nodes master:查看master的具体信息

[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    master   21h   v1.18.1
node     Ready    <none>   11h   v1.18.1
[root@master ~]# kubectl get nodes master
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    master   21h   v1.18.1

]# kubectl describe nodes node:查看node的详细信息

[root@master ~]# kubectl describe nodes node
Name:               master
Roles:              master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=master
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/master=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"f6:84:53:17:f1:dd"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.200.23
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Thu, 03 Dec 2020 09:06:51 -0500
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  master
  AcquireTime:     <unset>
  RenewTime:       Fri, 04 Dec 2020 06:54:24 -0500
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Thu, 03 Dec 2020 22:27:43 -0500   Thu, 03 Dec 2020 22:27:43 -0500   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Fri, 04 Dec 2020 06:50:07 -0500   Thu, 03 Dec 2020 09:06:46 -0500   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Fri, 04 Dec 2020 06:50:07 -0500   Thu, 03 Dec 2020 09:06:46 -0500   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Fri, 04 Dec 2020 06:50:07 -0500   Thu, 03 Dec 2020 09:06:46 -0500   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Fri, 04 Dec 2020 06:50:07 -0500   Thu, 03 Dec 2020 09:07:52 -0500   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.200.23
  Hostname:    master
Capacity:
  cpu:                2
  ephemeral-storage:  55269Mi
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             2853904Ki
  pods:               110
Allocatable:
  cpu:                2
  ephemeral-storage:  52158372164
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             2751504Ki
  pods:               110
System Info:
  Machine ID:                 50a4f08e13da4bde88f2d602c7ba0461
  System UUID:                290B4D56-7611-E667-5994-B3BF697C546F
  Boot ID:                    ca7e49a2-77ab-466d-a762-9395c80044af
  Kernel Version:             3.10.0-862.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://19.3.13
  Kubelet Version:            v1.18.1
  Kube-Proxy Version:         v1.18.1
PodCIDR:                      10.244.0.0/24
PodCIDRs:                     10.244.0.0/24
Non-terminated Pods:          (10 in total)
  Namespace                   Name                                          CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                   ----                                          ------------  ----------  ---------------  -------------  ---
  kube-system                 coredns-5d4768dfd-5vllb                       100m (5%)     0 (0%)      70Mi (2%)        170Mi (6%)     21h
  kube-system                 coredns-5d4768dfd-lrzgx                       100m (5%)     0 (0%)      70Mi (2%)        170Mi (6%)     21h
  kube-system                 etcd-master                                   0 (0%)        0 (0%)      0 (0%)           0 (0%)         21h
  kube-system                 kube-apiserver-master                         250m (12%)    0 (0%)      0 (0%)           0 (0%)         21h
  kube-system                 kube-controller-manager-master                200m (10%)    0 (0%)      0 (0%)           0 (0%)         21h
  kube-system                 kube-flannel-ds-27zsl                         100m (5%)     100m (5%)   50Mi (1%)        50Mi (1%)      21h
  kube-system                 kube-proxy-7kcmh                              0 (0%)        0 (0%)      0 (0%)           0 (0%)         21h
  kube-system                 kube-scheduler-master                         100m (5%)     0 (0%)      0 (0%)           0 (0%)         21h
  kubernetes-dashboard        dashboard-metrics-scraper-7cffc8f48c-h7tsq    0 (0%)        0 (0%)      0 (0%)           0 (0%)         21h
  kubernetes-dashboard        kubernetes-dashboard-67df665f7-m6zfg          0 (0%)        0 (0%)      0 (0%)           0 (0%)         21h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                850m (42%)  100m (5%)
  memory             190Mi (7%)  390Mi (14%)
  ephemeral-storage  0 (0%)      0 (0%)
  hugepages-1Gi      0 (0%)      0 (0%)
  hugepages-2Mi      0 (0%)      0 (0%)
Events:              <none>


Name:               node
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node
                    kubernetes.io/os=linux
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"76:fa:1d:1f:e7:47"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.200.24
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Thu, 03 Dec 2020 19:32:00 -0500
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  node
  AcquireTime:     <unset>
  RenewTime:       Fri, 04 Dec 2020 06:54:26 -0500
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Thu, 03 Dec 2020 20:35:12 -0500   Thu, 03 Dec 2020 20:35:12 -0500   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Fri, 04 Dec 2020 06:51:53 -0500   Fri, 04 Dec 2020 04:43:56 -0500   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Fri, 04 Dec 2020 06:51:53 -0500   Fri, 04 Dec 2020 04:43:56 -0500   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Fri, 04 Dec 2020 06:51:53 -0500   Fri, 04 Dec 2020 04:43:56 -0500   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Fri, 04 Dec 2020 06:51:53 -0500   Fri, 04 Dec 2020 04:43:56 -0500   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.200.24
  Hostname:    node
Capacity:
  cpu:                2
  ephemeral-storage:  38770180Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             1865308Ki
  pods:               110
Allocatable:
  cpu:                2
  ephemeral-storage:  35730597829
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             1762908Ki
  pods:               110
System Info:
  Machine ID:                 1193ed4bd708458fb3b1ede049c16b5a
  System UUID:                B3AC4D56-82A6-60EA-AA9A-0A385EE08896
  Boot ID:                    45a6027e-b368-43f5-84d3-5b3dc47f70b0
  Kernel Version:             3.10.0-862.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://19.3.13
  Kubelet Version:            v1.18.1
  Kube-Proxy Version:         v1.18.1
PodCIDR:                      10.244.1.0/24
PodCIDRs:                     10.244.1.0/24
Non-terminated Pods:          (4 in total)
  Namespace                   Name                     CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                   ----                     ------------  ----------  ---------------  -------------  ---
  default                     mysql                    0 (0%)        0 (0%)      0 (0%)           0 (0%)         12m
  default                     nginx                    0 (0%)        0 (0%)      0 (0%)           0 (0%)         7m52s
  kube-system                 kube-flannel-ds-9gvsf    100m (5%)     100m (5%)   50Mi (2%)        50Mi (2%)      11h
  kube-system                 kube-proxy-rrr8w         0 (0%)        0 (0%)      0 (0%)           0 (0%)         11h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                100m (5%)  100m (5%)
  memory             50Mi (2%)  50Mi (2%)
  ephemeral-storage  0 (0%)     0 (0%)
  hugepages-1Gi      0 (0%)     0 (0%)
  hugepages-2Mi      0 (0%)     0 (0%)
Events:              <none>

# kubectl describe pods nginx:查看pods中的Nginx的详细信息

[root@master ~]# kubectl describe pods nginx
Name:         nginx
Namespace:    default
Priority:     0
Node:         node/192.168.200.24
Start Time:   Fri, 04 Dec 2020 06:46:35 -0500
Labels:       run=nginx
Annotations:  <none>
Status:       Running
IP:           10.244.1.3
IPs:
  IP:  10.244.1.3
Containers:
  nginx:
    Container ID:   docker://9ea6ed6c3898ea20df942edf8cf9be3c2bc82c842816af83ea3f08dfa217357e
    Image:          192.168.200.23/library/nginx:1.14
    Image ID:       docker-pullable://192.168.200.23/library/nginx@sha256:706446e9c6667c0880d5da3f39c09a6c7d2114f5a5d6b74a2fafd24ae30d2078
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Fri, 04 Dec 2020 06:46:43 -0500
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-rjpwz (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-rjpwz:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-rjpwz
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age        From               Message
  ----    ------     ----       ----               -------
  Normal  Scheduled  <unknown>  default-scheduler  Successfully assigned default/nginx to node
  Normal  Pulling    9m40s      kubelet, node      Pulling image "192.168.200.23/library/nginx:1.14"
  Normal  Pulled     9m34s      kubelet, node      Successfully pulled image "192.168.200.23/library/nginx:1.14"
  Normal  Created    9m33s      kubelet, node      Created container nginx
  Normal  Started    9m33s      kubelet, node      Started container nginx


版权声明:本文为原创文章,版权归 Jun所有!

转载请注明出处:https://cranek.cn/?id=97

分享给朋友:

相关文章

kubernetes中的yaml文件

kubernetes中的yaml文件

注: 这里的C#代码,都是虚拟机命令一、yaml文件基础:    YAML是“YAML Ain't a Markup Langua”(YAML 不是一种标记语言)...

docker中的run命令

docker中的run命令

注: 这里的所有命令都是Linux系统中的命令,不是C#语言docker run :创建一个新的容器并运行一个命令   # docker run&nb...

mkdir: cannot create directory ‘docs/user-guide/configmap/kubectl’: No such file or directory

注: 这里的C#代码都是虚拟机的命令这样的问题,解决办法就是创建目录的时候加个 -p问题:[root@master ~]# mkdir docs/user-guide/c...

Unable to find image 'nginx:latest' locally

Unable to find image 'nginx:latest' locally

注: 这里的C#代码都是虚拟机中的命令今天在做运维的时候,有一个题目是这样的:在容器 server 节点创建/opt/xiandian-ro 目录,使用镜像 nginx:latest 创建名为 xia...

k8s创建pod

k8s创建pod

注: 这里的C#代码,是虚拟机终端的命令。Pod的模板文件:apiVersion: v1 kind: Pod metadata:   name: ...

K8S部署博客系统

K8S部署博客系统

部署博客系统配置NFS服务master 节点安装 NFS 与 RPC 服务:# yum install -y nfs-utils rpcbindnode 节点安装 NFS 客户端:# yum inst...