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 ...
随机推荐
- 基于CXF开发crm服务
1 基于CXF开发crm服务 1.1 数据库环境搭建 1.2 web项目环境搭建 第一步:创建动态web项目 第二步:导入CXF相关jar包 第三步:配置web.xml <context-par ...
- Java 程序设计总复习题
Java程序设计总复习题 1.编写一个Java程序在屏幕上输出“你好!”. //programme name Helloworld.java public class Helloworld { pub ...
- c++ 程序设计question 001:我们的开发工具是什么?
我们使用的开发工具是dev cpp (c plus plus),这是一个集成开发环境,我们称之为IDE(integrated development environment)
- 问题002:我们要使用的Java是哪个版本的?什么是JVM、JRE、JDK、IDE、API?
三个版本:1.java SE 标准版 2.java EE企业版 3.Java ME 小型版本 JVM (java virtual machine) java虚拟机 JRE(java runtime e ...
- Android驱动开发读书笔记七
第七章 (一)创建设备文件 1.使用cdev_init函数初始化cdec 描述设备文件需要一个cdev结构体,代码如下: struct cdev{ struct kobject kobj; struc ...
- web前端-回调函数sort详解
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- ATM-core-src
from interface import bank, shopping, userfrom lib import common user_data = { 'name': None} def log ...
- vue.js 独立引用css文件图片路径错误
vue的环境是用vue-cli,写在vue文件的图片引用build之后的路径都没什么问题 但是有的时候我们会有一些公共的css文件单独的放在assets目录下 如下图所示 这里当build后发现写在c ...
- 微信小程序 onLoad 函数
小程序注册完成后,加载页面,触发onLoad方法. 页面载入后触发onShow方法,显示页面. 首次显示页面,会触发onReady方法,渲染页面元素和样式,一个页面只会调用一次. 当小程序后台运行或跳 ...
- 第1-5章 慕课网微信小程序开发学习笔记
第1章 前言:不同的时代,不同的Web --微信小程序商城构建全栈应用 http://note.youdao.com/noteshare?id=a0e9b058853dbccf886c1a890594 ...