Kubectl管理工具
1、常用指令如下


运行应用程序
[root@manager ~]# kubectl run hello-world --replicas=3 --labels="app=example" --image=nginx:1.10 --port=80
[root@manager ~]# kubectl get pods --selector="app=example"
NAME READY STATUS RESTARTS AGE
hello-world-cc85d4fb6-btsvz / ContainerCreating 33s
hello-world-cc85d4fb6-mtg75 / ContainerCreating 33s
hello-world-cc85d4fb6-r57vx / ContainerCreating 33s
[root@manager ~]# [root@manager ~]# kubectl describe pod hello-world-cc85d4fb6-btsvz
Name: hello-world-cc85d4fb6-btsvz
Namespace: default
Node: 192.168.10.221/192.168.10.221
Start Time: Fri, Feb :: +
Labels: app=example
pod-template-hash=
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"hello-world-cc85d4fb6","uid":"98254448-07be-11e8-af8c-5254002bf2...
Status: Pending
IP:
Created By: ReplicaSet/hello-world-cc85d4fb6
Controlled By: ReplicaSet/hello-world-cc85d4fb6
Containers:
hello-world:
Container ID:
Image: nginx:1.10
Image ID:
Port: /TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count:
Environment: <none>
Mounts: <none>
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
Volumes: <none>
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 1m default-scheduler Successfully assigned hello-world-cc85d4fb6-btsvz to 192.168.10.221
Normal Pulling 1m kubelet, 192.168.10.221 pulling image "nginx:1.10"
Normal Pulled 6s kubelet, 192.168.10.221 Successfully pulled image "nginx:1.10"
查看pod所属标签
[root@manager ~]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
busybox / Running 1d <none>
busybox2 / Running 1d <none>
hello-world-cc85d4fb6-btsvz / Running 2m app=example,pod-template-hash=
hello-world-cc85d4fb6-mtg75 / Running 2m app=example,pod-template-hash=
hello-world-cc85d4fb6-r57vx / Running 2m app=example,pod-template-hash=774180962 根据标签查看pod
[root@manager ~]# kubectl get pods -l app=example -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP          NODE
hello-world-cc85d4fb6-btsvz   1/1       Running   0          3m        10.0.91.5   192.168.10.221
hello-world-cc85d4fb6-mtg75   1/1       Running   0          3m        10.0.71.8   192.168.10.222
hello-world-cc85d4fb6-r57vx   1/1       Running   0          3m        10.0.91.6   192.168.10.221
显示有关deployment信息
[root@manager ~]# kubectl get deployments hello-world
NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-world   3         3         3            3           3m
[root@manager ~]# 
[root@manager ~]# kubectl describe deployments hello-world
Name:                   hello-world
Namespace:              default
CreationTimestamp:      Fri, 02 Feb 2018 10:13:01 +0800
Labels:                 app=example
Annotations:            deployment.kubernetes.io/revision=1
Selector:               app=example
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:  app=example
  Containers:
   hello-world:
    Image:        nginx:1.10
    Port:         80/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   hello-world-cc85d4fb6 (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  4m    deployment-controller  Scaled up replica set hello-world-cc85d4fb6 to 3
显示有关rs信息
[root@manager ~]# kubectl get replicasets
NAME                    DESIRED   CURRENT   READY     AGE
hello-world-cc85d4fb6   3         3         3         4m
[root@manager ~]# 
[root@manager ~]# kubectl describe replicasets
Name:           hello-world-cc85d4fb6
Namespace:      default
Selector:       app=example,pod-template-hash=774180962
Labels:         app=example
                pod-template-hash=774180962
Annotations:    deployment.kubernetes.io/desired-replicas=3
                deployment.kubernetes.io/max-replicas=4
                deployment.kubernetes.io/revision=1
Controlled By:  Deployment/hello-world
Replicas:       3 current / 3 desired
Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=example
           pod-template-hash=774180962
  Containers:
   hello-world:
    Image:        nginx:1.10
    Port:         80/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  4m    replicaset-controller  Created pod: hello-world-cc85d4fb6-btsvz
  Normal  SuccessfulCreate  4m    replicaset-controller  Created pod: hello-world-cc85d4fb6-mtg75
  Normal  SuccessfulCreate  4m    replicaset-controller  Created pod: hello-world-cc85d4fb6-r57vx
扩容pod数量
[root@manager ~]# kubectl scale deployment --replicas=5 hello-world
deployment "hello-world" scaled
[root@manager ~]# 
[root@manager ~]# kubectl get pods --selector="app=example" -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP          NODE
hello-world-cc85d4fb6-btsvz   1/1       Running   0          5m        10.0.91.5   192.168.10.221
hello-world-cc85d4fb6-mppx2   1/1       Running   0          17s       10.0.71.9   192.168.10.222
hello-world-cc85d4fb6-mtg75   1/1       Running   0          5m        10.0.71.8   192.168.10.222
hello-world-cc85d4fb6-r57vx   1/1       Running   0          5m        10.0.91.6   192.168.10.221
hello-world-cc85d4fb6-xgv4z   1/1       Running   0          17s       10.0.91.7   192.168.10.221
创建一个Service对象暴露Deployment(在88端口负载TCP流量)
[root@manager ~]# kubectl expose deployment hello-world --port= --type=NodePort --target-port= --name=example-service
service "example-service" exposed
[root@manager ~]#
[root@manager ~]# kubectl describe services example-service
Name: example-service
Namespace: default
Labels: app=example
Annotations: <none>
Selector: app=example
Type: NodePort
IP: 10.10.10.11
Port: <unset> /TCP
TargetPort: /TCP
NodePort: <unset> /TCP
Endpoints: 10.0.71.8:,10.0.71.9:,10.0.91.5: + more...
Session Affinity: None
External Traffic Policy: Cluster
Events: <none> 使用节点IP和节点端口访问应用程序
[root@node1 ~]# curl 10.10.10.11:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>

清理应用
kubectl delete services example-service
kubectl delete deployment hello-world
[root@manager ~]# kubectl get all
NAME READY STATUS RESTARTS AGE
po/busybox / Running 1d
po/busybox2 / Running 1d NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes ClusterIP 10.10.10.1 <none> /TCP 2d
yaml配置文件管理资源
配置文件说明:
定义配置时,指定最新稳定版API(当前为v1);
配置文件应该存储在集群之外的版本控制仓库中。如果需要,可以快速回滚配置、重新创建和恢复;
应该使用YAML格式编写配置文件,而不是JSON。尽管这些格式都可以使用,但YAML对用户更加友好;
可以将相关对象组合成单个文件,通常会更容易管理;
不要没必要的指定默认值,简单和最小配置减少错误;
在注释中说明一个对象描述更好维护。
[root@manager ~]#
[root@manager ~]# cat nginx-deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: [root@manager ~]# kubectl create -f nginx-deployment.yaml
deployment "nginx-deployment" created
[root@manager ~]# cat nginx-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
spec:
  ports:
  - port: 88
    targetPort: 80
  selector:
    app: nginx

[root@manager ~]# 
[root@manager ~]# kubectl create -f nginx-service.yaml 
service "nginx-service" created
[root@manager ~]# 
[root@manager ~]# 
[root@manager ~]# kubectl get svc 
NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes      ClusterIP   10.10.10.1     <none>        443/TCP   2d
nginx-service   ClusterIP   10.10.10.243   <none>        88/TCP    9s
[root@manager ~]# kubectl describe services nginx-service
Name:              nginx-service
Namespace:         default
Labels:            app=nginx
Annotations:       <none>
Selector:          app=nginx
Type:              ClusterIP
IP:                10.10.10.243
Port:              <unset>  88/TCP
TargetPort:        80/TCP
Endpoints:         10.0.71.8:80,10.0.71.9:80,10.0.91.5:80
Session Affinity:  None
Events:            <none>

Kubectl管理工具的更多相关文章
- 第4章:kubectl命令行管理工具
		
kubectl --help 查看帮助信息 kubectl create --help 查看create命令帮助信息 命令 描述 create 通过文件名或标准输入创建资源 expose 将一个资源公 ...
 - kubectl插件管理工具krew
		
文章转载自:https://blog.51cto.com/loong576/2452592 一.k8s核心组件 Kubernetes 主要由以下几个核心组件组成: etcd 保存了整个集群的状态: a ...
 - Helm包管理工具(简介、安装、方法)
		
认识Helm 每次我们要部署一个应用都需要写一个配置清单(维护一套yaml文件),但是每个环境又不一样.部署一套新的环境成本是真的很高.如果我们能够使用类似于yum的工具来安装我们的应用的话那就太好了 ...
 - 使用 Helm 包管理工具简化 Kubernetes 应用部署
		
当在 Kubernetes 中已经部署很多应用时,后续需要对每个应用的 yaml 文件进行维护操作,这个过程会变的很繁琐,我们可以使用 Helm 来简化这些工作.Helm 是 Kubernetes 的 ...
 - Docker集群管理工具 - Kubernetes 部署记录  (运维小结)
		
一. Kubernetes 介绍 Kubernetes是一个全新的基于容器技术的分布式架构领先方案, 它是Google在2014年6月开源的一个容器集群管理系统,使用Go语言开发,Kubernete ...
 - kubectl客户端工具远程连接k8s集群
		
一.概述 一般情况下,在k8smaster节点上集群管理工具kubectl是连接的本地http8080端口和apiserver进行通讯的,当然也可以通过https端口进行通讯前提是要生成证书.所以说k ...
 - k8s包管理工具helm - 介绍和安装
		
目录 1.Kubernetes 应用部署的挑战 2.Helm 是什么 3.Helm 组件及相关术语 4.Helm 工作原理 5.Helm 安装 5.1 客户端安装 5.2 安装服务端 Tiller 5 ...
 - 这么高颜值的Kubernetes管理工具Lens,难道还不能C位出道吗
		
1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! Docker & Kubernetes相关文章:容器技术 一直使用官方的Kubernetes Dashboard来管 ...
 - helm包管理工具
		
K8S正常部署应用是如下方式 kubectl create deployment web --image=nginx --dru-run=client -o yaml > web.yaml ku ...
 
随机推荐
- USACO09FEB Fair Shuttle
			
题目传送门 据说\(NOIp\)前发题解可以\(\mathfrak{RP}\)++ 因为要尽可能满足更多奶牛,所以按照这种区间贪心题的套路,先按右端点排序,然后依次遍历,能坐车的就让它们坐车,这样一定 ...
 - java设计模式——单例模式(三)
			
容器单例模式 之前学习Structs2,Spring框架时,经常会听到单例,多例.虽然这与单例模式不太一样,但是都很类似.在程序运行的时候,就加载所有的实例,然后用的时候直接取出 看下面代码: /** ...
 - XGBoost算法原理小结
			
在两年半之前作过梯度提升树(GBDT)原理小结,但是对GBDT的算法库XGBoost没有单独拿出来分析.虽然XGBoost是GBDT的一种高效实现,但是里面也加入了很多独有的思路和方法,值得单独讲一讲 ...
 - BeyondCompare:如何之比较文件内容的不同?
			
问题描述: 在使用beyond compare比较文件的时候,常会有很多不同,但是点击打开后,发现内容没有不同.这个是因为工具把文件的日期.大小等非内容因素也比较了进去. 解决方法: 点击“会话” - ...
 - POI  Excel  插入新的行,下面的行动态移动
			
在做Excel 模板时,会有遇到 模板行数不固定,如下图 需要在行次4下面再插入一行:注意:(插入的行如果是下面空白行,需要创建行) 解决方法是使用shifRows方法,第1个参数是指要开始插入的 ...
 - Linux清空mysql所有数据
			
1,删除data目录下所有文件 rm -rf /usr/local/mysql5/data/* 2,mysql_install_db脚本初始化Mysql /usr/local/mysql5/scrip ...
 - 809. Expressive Words
			
https://leetcode.com/problems/expressive-words/description/ class Solution { public: int expressiveW ...
 - 动态规划:HDU2571-命运
			
解题心得: 1.其实是一个简单的动态规划加上贪心的思想,思路简单,只需要求每一步的最大值就可以了,但是要注意读懂题. 2.走的规则:从左上角开始走,达到右下角,只能向右走一步,或者向下走一步,或者走列 ...
 - 递推:Number Sequence(mod找规律)
			
解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...
 - springboot学习资料汇总
			
收集Spring Boot相关的学习资料,Spring Cloud点这里 推荐博客 纯洁的微笑 程序猿DD liaokailin的专栏 Spring Boot 揭秘与实战 系列 catoop的专栏 简 ...