the .

首先要理解,下面几个概念命令,命令基本也是针对这些概念而言的。

node

pods

///////////////////////////////////////////////////////////////////////////////////

描述资源对象

nodes # 显示Node的详细信息

pods

# 显示Pod的详细信息

首先 下面2个命令默认结果一致

nodes

node

页面中,也仅仅只有一个node –

:8001/api/v1//-//https:-:/proxy/#/node?=_all

   ➜  ~ kubectl describe node
Name:               docker-desktop
这个名字是第一行的输出
后翻可以看到namespace

node –

这个输出很详细,有输出信息

kube-

个人觉得 node比 get nodes获取的信息更多一些

➜  ~ kubectl get nodes docker-desktop
NAME             STATUS   ROLES    AGE   VERSION
docker-desktop   Ready    master   17h   v1.18.8
kubectl get 显示一个或更多resources资源
kubectl get cs                          # 查看集群状态
kubectl get nodes                       # 查看集群节点信息
kubectl get ns                          # 查看集群命名空间
kubectl get svc -n kube-system          # 查看指定命名空间的服务
kubectl get pod  -o wide      # 查看Pod详细信息
kubectl get pod  -o yaml      # 以yaml格式查看Pod详细信息
kubectl get pods                        # 查看资源对象,查看所有Pod列表
kubectl get rc,service                  # 查看资源对象,查看rc和service列表
kubectl get pod,svc,ep --show-labels    # 查看pod,svc,ep能及标签信息
kubectl get all --all-namespaces        # 查看所有的namespaces

-info 显示集群信息

➜  ~ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'

查看创建的pod

:8001/api/v1//-//https:-:/proxy/#/pod?=_all

查看所有 pod 列表, -n 后跟 , 查看指定的命名空间

通过界面能看到有2个

kube-

Examples:
  # List all pods in ps output format.
  kubectl get pods
➜  ~ kubectl get pods -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-694557449d-7h8k6   1/1     Running   0          16h
kubernetes-dashboard-7d9ddf9f8f-wprd7        1/1     Running   0          16h
➜  ~ kubectl get pods -n kube-system
NAME                                     READY   STATUS    RESTARTS   AGE
coredns-66bff467f8-5qhsc                 1/1     Running   0          17h
coredns-66bff467f8-wdzmj                 1/1     Running   0          17h
etcd-docker-desktop                      1/1     Running   0          17h
kube-apiserver-docker-desktop            1/1     Running   5          17h
kube-controller-manager-docker-desktop   1/1     Running   5          17h
kube-proxy-fj96d                         1/1     Running   0          17h
kube-scheduler-docker-desktop            1/1     Running   0          17h
storage-provisioner                      1/1     Running   0          17h
vpnkit-controller                        1/1     Running   0          17h
➜  ~ kubectl get pods -n kube-system kube-scheduler-docker-desktop
NAME                            READY   STATUS    RESTARTS   AGE
kube-scheduler-docker-desktop   1/1     Running   0          16h
➜  ~ kubectl get pods -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-694557449d-7h8k6   1/1     Running   0          16h
kubernetes-dashboard-7d9ddf9f8f-wprd7        1/1     Running   0          16h

查看svc信息

➜  ~ kubectl describe svc
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       
Selector:          
Type:              ClusterIP
IP:                10.96.0.1
Port:              https  443/TCP
TargetPort:        6443/TCP
Endpoints:         192.168.65.3:6443
Session Affinity:  None
Events:            

查看 所有的

➜  ~  kubectl get services -A
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP   10.96.0.1                443/TCP                  17h
kube-system            kube-dns                    ClusterIP   10.96.0.10               53/UDP,53/TCP,9153/TCP   17h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.102.121.205           8000/TCP                 16h
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.98.196.76             443/TCP                  16h
-n后面跟 NAMESPACE
➜  ~ kubectl get service -n kube-system -o wide
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE   SELECTOR
kube-dns   ClusterIP   10.96.0.10           53/UDP,53/TCP,9153/TCP   16h   k8s-app=kube-dns
➜  ~ kubectl get service -n kube-system -o wide
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE   SELECTOR
kube-dns   ClusterIP   10.96.0.10           53/UDP,53/TCP,9153/TCP   15h   k8s-app=kube-dns
➜  ~ kubectl get service -n kubernetes-dashboard
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
dashboard-metrics-scraper   ClusterIP   10.102.121.205           8000/TCP   16h
kubernetes-dashboard        ClusterIP   10.98.196.76             443/TCP    16h

# 根据 yaml 创建资源, apply 可以重复执行, 不行

kubectl create -f pod.yaml
kubectl apply -f pod.yaml

run 在集群中运行一个指定的镜像

参考:

run后面跟pods 为 nginx
➜  ~ kubectl run nginx --image=centos --port=80 --replicas=1
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/nginx created
可以看到上面这个命令术不会被弃用
并且只创建一个nginx 容器实例
在K8S v1.18.0 以后,--replicas已弃用 ,推荐用 deployment 创建 pod。
如果需要创建可以通过如下方式操作:
kubectl apply -f nginx.yaml
This action is equivalent to:kubectl apply -f 
➜  ~ kubectl run nginx --image=centos --port=80
pod/nginx created
➜  ~ kubectl logs nginx
Error from server (BadRequest): container "nginx" in pod "nginx" is waiting to start: ContainerCreating
查看这个pods nginx的状态  kubectl describe pods nginx
kubctl获取pod状态
➜  ~ kubectl get pods nginx
NAME    READY   STATUS             RESTARTS   AGE
nginx   0/1     CrashLoopBackOff   37         168m
查询异常pod名称为 nginx
查看此状态pod详细情况
➜  ~ kubectl describe pods nginx
这里能看到获取的IP地址10.1.0.10
查看此pod日志
kubectl logs nginx
这里日志是空的,所以
我现在删除这个pods nginx
kubectl delete pods nginx
pod "nginx" deleted
//////////下面是OK的过程/////////
再次简单启动:
➜  ~ kubectl run nginx --image=nginx

查看日志

➜  ~ kubectl logs nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
10.1.0.10 - - [14/Oct/2020:08:54:59 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.64.0" "-"
10.1.0.10 - - [14/Oct/2020:08:55:07 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.64.0" "-"

下面请求下看看,而且日志已经记录了

执行 pod 的 命令比如curl

➜ ~ exec nginx — curl -I 10.1.0.10

% Total % % Xferd Speed Time Time Time

Dload Total Spent Left Speed

0 612 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0

———END———
限 时 特 惠: 本站每日持续更新海量各大内部创业教程,永久会员只需109元,全站资源免费下载 点击查看详情
站 长 微 信: nanadh666

声明:1、本内容转载于网络,版权归原作者所有!2、本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。3、本内容若侵犯到你的版权利益,请联系我们,会尽快给予删除处理!