kubectl工具管理应用
Posted zc1741845455
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubectl工具管理应用相关的知识,希望对你有一定的参考价值。
kubectl工具管理应用
创建一个pod
[[email protected] ~]# kubectl run nginx --replicas=3 --labels="app=nginx-example" --image=nginx:1.10 --port=80
查看所有资源信息
[[email protected] ~]# 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的详细信息
[[email protected] ~]# kubectl describe po/nginx-f95d765f9-8b6bp
查看创建的pod
[[email protected] ~]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-f95d765f9 3 3 3 11m
查看创建的pod
[[email protected] ~]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 3 3 3 3 13m
查看集群
[[email protected] ~]# 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
[[email protected] ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 1d
查看pod的标签
[[email protected] ~]# 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
[[email protected] ~]# kubectl run busybox --image=busybox --command -- ping baidu.com
查看指定的标签
[[email protected] ~]# kubectl get pods -l run=busybox
NAME READY STATUS RESTARTS AGE
busybox-5d4f595646-dzjv4 1/1 Running 0 4m
查看pod分配到哪个节点上
[[email protected] ~]# 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
查看标签并运行了哪些镜像或容器
[[email protected] ~]# 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这个标签进行创建
[[email protected] ~]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service
查看标签
[[email protected] ~]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
busybox 1 1 1 1 14m
nginx 3 3 3 3 36m
查看service,端口已经暴露给用户
[[email protected] ~]# 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
Node1和node2都可以访问
内部访问
[[email protected] ~]# curl 10.10.10.173:88
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[[email protected] ~]# 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工具管理应用的主要内容,如果未能解决你的问题,请参考以下文章