码迷,mamicode.com
首页 > 其他好文 > 详细

kubectl工具管理应用

时间:2019-07-05 19:15:39      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:erro   图片   image   style   health   pos   label   应用   tor   

kubectl工具管理应用

创建一个pod

[root@k8s-master ~]# kubectl run nginx --replicas=3 --labels="app=nginx-example" --image=nginx:1.10 --port=80

 

查看所有资源信息

[root@k8s-master ~]# kubectl get all

NAME                       READY     STATUS    RESTARTS   AGE

po/nginx-f95d765f9-8b6bp   1/1       Running   0          3m

po/nginx-f95d765f9-cfm6d   1/1       Running   0          3m

po/nginx-f95d765f9-lktk6   1/1       Running   0          3m

 

查看pod的详细信息

[root@k8s-master ~]# kubectl describe po/nginx-f95d765f9-8b6bp

 

查看创建的pod

[root@k8s-master ~]# kubectl get rs

NAME              DESIRED   CURRENT   READY     AGE

nginx-f95d765f9   3         3         3         11m

 

查看创建的pod

[root@k8s-master ~]# kubectl get deploy

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE

nginx     3         3         3            3           13m

 

查看集群

[root@k8s-master ~]# kubectl get cs

\NAME                 STATUS    MESSAGE              ERROR

scheduler            Healthy   ok                   

controller-manager   Healthy   ok                   

etcd-2               Healthy   {"health": "true"}   

etcd-1               Healthy   {"health": "true"}   

etcd-0               Healthy   {"health": "true"}

 

查看service

[root@k8s-master ~]# kubectl get svc

NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE

kubernetes   ClusterIP   10.10.10.1   <none>        443/TCP   1d

 

查看pod的标签

[root@k8s-master ~]# kubectl get pods --show-labels

NAME                    READY     STATUS    RESTARTS   AGE       LABELS

nginx-f95d765f9-8b6bp   1/1       Running   0          19m       app=nginx-example,pod-template-hash=951832195

nginx-f95d765f9-cfm6d   1/1       Running   0          19m       app=nginx-example,pod-template-hash=951832195

nginx-f95d765f9-lktk6   1/1       Running   0          19m       app=nginx-example,pod-template-hash=951832195

 

创建一个pod

[root@k8s-master ~]# kubectl run busybox --image=busybox --command -- ping baidu.com

 

查看指定的标签

[root@k8s-master ~]# kubectl get pods -l run=busybox

NAME                       READY     STATUS    RESTARTS   AGE

busybox-5d4f595646-dzjv4   1/1       Running   0          4m

 

查看pod分配到哪个节点上

[root@k8s-master ~]# kubectl get pods -o wide

NAME                       READY     STATUS    RESTARTS   AGE       IP            NODE

busybox-5d4f595646-dzjv4   1/1       Running   0          5m        172.17.11.4   192.168.30.22

nginx-f95d765f9-8b6bp      1/1       Running   0          27m       172.17.11.2   192.168.30.22

nginx-f95d765f9-cfm6d      1/1       Running   0          27m       172.17.80.2   192.168.30.23

nginx-f95d765f9-lktk6      1/1       Running   0          27m       172.17.11.3   192.168.30.22

 

查看标签并运行了哪些镜像或容器

[root@k8s-master ~]# kubectl get deploy -o wide

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES       SELECTOR

busybox   1         1         1            1           8m        busybox      busybox      run=busybox

nginx     3         3         3            3           29m       nginx        nginx:1.10   app=nginx-example

 

发布并暴露端口使用户可以访问

根据nginx这个标签进行创建

[root@k8s-master ~]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service

 

查看标签

[root@k8s-master ~]# kubectl get deploy

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE

busybox   1         1         1            1           14m

nginx     3         3         3            3           36m

 

查看service,端口已经暴露给用户

[root@k8s-master ~]# kubectl get svc

NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE

kubernetes      ClusterIP   10.10.10.1     <none>        443/TCP        1d

nginx-service   NodePort    10.10.10.173   <none>        88:35442/TCP   1m

 

Node1node2都可以访问

内部访问

[root@k8s-node1 ~]# curl 10.10.10.173:88

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

[root@k8s-node2 ~]# curl 10.10.10.173:88

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

 

用户可通过外部访问我们的应用

访问http://192.168.30.22:35442

技术图片

访问http://192.168.30.23:35442

技术图片

 

kubectl工具管理应用

标签:erro   图片   image   style   health   pos   label   应用   tor   

原文地址:https://www.cnblogs.com/zc1741845455/p/11140009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!