标签和选择器

This commit is contained in:
huanqing.shao
2019-10-15 20:15:40 +08:00
parent 1698c0ed68
commit a30f08d14d
13 changed files with 262 additions and 23 deletions

View File

@ -1,5 +1,5 @@
<template>
<div class="adsense-left-top">
<div class="adsense-left-top" v-if="$site.showMoreAds">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- AdsenseLeftTop -->
<ins class="adsbygoogle"

View File

@ -1,5 +1,5 @@
<template>
<div class="adsense-page-top" v-if="!$frontmatter.lessAds">
<div class="adsense-page-top" v-if="!$frontmatter.lessAds && $site.showMoreAds">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- AdSensePageTop-Display -->
<ins class="adsbygoogle"

View File

@ -29,11 +29,11 @@ export default {
.adsense-right {
width: calc(50vw - 700px);
max-width: 450px;
height: 50vh;
max-height: 30vh;
position: fixed;
bottom: 80px;
right: 10px;
/* background-color: grey; */
background-color: grey;
}
</style>

View File

@ -38,6 +38,9 @@
:item="actionLink2"
/>
</span>
<p>
<StarCount></StarCount>
</p>
</header>
<div

View File

@ -0,0 +1,15 @@
<template>
<a aria-label="github" @click="$sendGaEvent('ViewGitHubStar', 'ViewGitHubStarNav', 'ViweGitHubStar:' + $page.path)">
<iframe style="display:inline-block;vertical-align:middle;" src="https://ghbtns.com/github-btn.html?user=eip-work&amp;repo=kuboard-press&amp;type=star&amp;count=true&amp;size=small" frameborder="0" scrolling="0" width="100px" height="20px"></iframe>
</a>
</template>
<script>
export default {
}
</script>
<style>
</style>

View File

@ -3,6 +3,7 @@ let dateFns = require('date-fns')
module.exports = {
title: 'Kuboard官网',
description: '一款Kubernetes_Dashboard_简化Kubernetes的学习和使用_帮助您快速落地Kubernetes_提供_Kubernetes_免费中文教程_国内安装文档',
showMoreAds: false,
head: [
// ['meta', {name: 'keywords', content: 'Kubernetes教程,Kubernetes安装,K8S教程,K8S安装,Kubernetes管理界面'}],
['link', { rel: 'icon', href: '/favicon.png' }],
@ -288,6 +289,7 @@ module.exports = {
'k8s-intermediate/obj/names',
'k8s-intermediate/obj/namespaces',
'k8s-intermediate/obj/namespace-op',
'k8s-intermediate/obj/labels',
]
},
{

View File

@ -24,9 +24,7 @@
<a href="/learning/">
<span style="color: #42b983;">提供K8S免费教程</span>
</a>
<a style="margin-left: 10px;" aria-label="github">
<iframe style="display:inline-block;vertical-align:middle;" src="https://ghbtns.com/github-btn.html?user=eip-work&amp;repo=kuboard-press&amp;type=star&amp;count=true&amp;size=small" frameborder="0" scrolling="0" width="100px" height="20px"></iframe>
</a>
<StarCount style="margin-left: 10px;"></StarCount>
<a href="https://webscan.qianxin.com/safe/detail/?query=kuboard.cn"><img border="0" src="https://webscan.qianxin.com/api/authcode?code=ab3ebe0592248d28477251ecaf72154f" style="display: none;"/></a>
<!-- <span style="color: #2c3e50;">|</span>
<a href="/support/#%E5%BE%AE%E6%9C%8D%E5%8A%A1%E8%90%BD%E5%9C%B0%E5%92%A8%E8%AF%A2">

View File

@ -40,7 +40,10 @@ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-b
## 访问
Kubernetes Dashboard 默认部署时,只配置了最低权限的 RBAC。当前,只支持使用 Bearer Token登录。
Kubernetes Dashboard 当前,只支持使用 Bearer Token登录。
由于 Kubernetes Dashboard 默认部署时,只配置了最低权限的 RBAC。因此我们要创建一个名为 `admin-user` 的 ServiceAccount再创建一个 ClusterRolebinding将其绑定到 Kubernetes 集群中默认初始化的 `cluster-admin` 这个 ClusterRole。
> 更多关于权限管理的信息,请参考 [Using RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)
* 创建 Service Account

View File

@ -122,7 +122,7 @@ export default {
* **持续更新和完善**
* 始终有最新的 Kubernetes 稳定版安装文档,当前版本 v1.16.1
* 当前已更新了 <font color="red"> 59</font> [查看更新历史](https://github.com/eip-work/kuboard-press/commits/master/install/install-k8s.md)
* 当前已更新了 <font color="red"> 60</font> [查看更新历史](https://github.com/eip-work/kuboard-press/commits/master/install/install-k8s.md)
* **在线答疑**
@ -272,15 +272,15 @@ echo "127.0.0.1 $(hostname)" >> /etc/hosts
::: danger 必须选中下面的四个勾选框才能继续
* 选中后显示 **安装 docker/kubelet 的文档**
<div style="display: inline-block; width: 480px; line-height: 40px; background-color: rgba(255,229,100,0.3); padding: 20px 0 0 20px; margin-bottom: 20px; border: 1px solid #d7dae2;">
<div style="display: inline-block; width: 480px; max-width: calc(100vw - 100px); overflow: hidden; line-height: 40px; background-color: rgba(255,229,100,0.3); padding: 20px 0 0 20px; margin-bottom: 20px; border: 1px solid #d7dae2;">
<el-form :model="form" ref="envForm" :rules="rules" style="text-align: left;">
<el-form-item prop="checked" class="env-form-item">
<el-checkbox-group v-model="form.checked">
<li style="height: 40px;"> <el-checkbox style="width: 300px; text-align: left;" label="centos">我的任意节点 centos 版本在兼容列表中</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; text-align: left;" label="hostname">我的任意节点 hostname 不是 localhost且不包含下划线</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; text-align: left;" label="cpu">我的任意节点 CPU 内核数量大于等于 2</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; text-align: left;" label="docker">我的任意节点不会直接使用 docker run 或 docker-compose 运行容器</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; text-align: left;" label="networkcard">我的任意节点只有一块网卡可以在完成K8S安装后再添加网卡</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; max-width: calc(100vw - 100px); text-align: left;" label="centos">我的任意节点 centos 版本在兼容列表中</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; max-width: calc(100vw - 100px); text-align: left;" label="hostname">我的任意节点 hostname 不是 localhost且不包含下划线</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; max-width: calc(100vw - 100px); text-align: left;" label="cpu">我的任意节点 CPU 内核数量大于等于 2</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; max-width: calc(100vw - 100px); text-align: left;" label="docker">我的任意节点不会直接使用 docker run 或 docker-compose 运行容器</el-checkbox> </li>
<li style="height: 40px;"> <el-checkbox style="width: 300px; max-width: calc(100vw - 100px); text-align: left;" label="networkcard">我的任意节点只有一块网卡可以在完成K8S安装后再添加网卡</el-checkbox> </li>
</el-checkbox-group>
</el-form-item>
</el-form>
@ -558,7 +558,7 @@ kubectl delete -f https://kuboard.cn/install-script/v1.16.1/nginx-ingress.yaml
</a>
::: tip
* Kubernetes 初学者,[点击这里获取 Kubernetes 学习路径](/overview/#kubernetes-%E5%88%9D%E5%AD%A6%E8%80%85)
* Kubernetes 初学者,[点击这里获取 Kubernetes 学习路径](/learning/)
:::

View File

@ -0,0 +1,14 @@
---
# vssueId: 133
layout: LearningLayout
description: Kubernetes教程_标签Label是附加在Kubernetes对象上的一组名值对_其意图是按照对用户有意义的方式来标识Kubernetes对象_同时_又不对Kubernetes的核心逻辑产生影响_标签可以用来组织和选择一组Kubernetes对象
meta:
- name: keywords
content: Kubernetes 教程,Kubernetes Annotation,Kubernetes 注解
---
# 注解 annotation
<AdSenseTitle>
</AdSenseTitle>

View File

@ -1,14 +1,208 @@
---
# vssueId: 133
vssueId: 137
layout: LearningLayout
description: Kubernetes教程_本文描述了Kubernetes对象与Kubernetes_API的关系_以及您如何在.yaml格式的文件中定义Kubernetes对象
description: Kubernetes教程_标签Label是附加在Kubernetes对象上的一组名值对_其意图是按照对用户有意义的方式来标识Kubernetes对象_同时_又不对Kubernetes的核心逻辑产生影响_标签可以用来组织和选择一组Kubernetes对象
meta:
- name: keywords
content: Kubernetes对象,Kubernetes Object
content: Kubernetes 教程,Kubernetes Labels,Kubernetes Selector
---
# Labels and Selectors
# 标签和选择器
<AdSenseTitle />
<AdSenseTitle>
正在撰写 ...
标签Label是附加在Kubernetes对象上的一组名值对其意图是按照对用户有意义的方式来标识Kubernetes对象同时又不对Kubernetes的核心逻辑产生影响。标签可以用来组织和选择一组Kubernetes对象。您可以在创建Kubernetes对象时为其添加标签也可以在创建以后再为其添加标签。每个Kubernetes对象可以有多个标签同一个对象的标签的 Key 必须唯一,例如:
``` yaml
metadata:
labels:
key1: value1
key2: value2
```
使用标签Label可以高效地查询和监听Kubernetes对象在Kubernetes界面工具如 Kubenetes Dashboard 或 Kuboard和 kubectl 中,标签的使用非常普遍。那些非标识性的信息应该记录在[注解annotation](./annotations.html)
[[TOC]]
</AdSenseTitle>
## 为什么要使用标签
使用标签,用户可以按照自己期望的形式组织 Kubernetes 对象之间的结构,而无需对 Kubernetes 有任何修改。
应用程序的部署或者批处理程序的部署通常都是多维度的(例如,多个高可用分区、多个程序版本、多个微服务分层)。管理这些对象时,很多时候要针对某一个维度的条件做整体操作,例如,将某个版本的程序整体删除,这种情况下,如果用户能够事先规划好标签的使用,再通过标签进行选择,就会非常地便捷。
标签的例子有:
* `release: stable`、`release: canary`
* `environment: dev`、`environment: qa`、`environment: production`
* `tier: frontend`、`tier: backend`、`tier: cache`
* `partition: customerA`、`partition: customerB`
* `track: daily`、`track: weekly`
上面只是一些使用比较普遍的标签,您可以根据您自己的情况建立合适的使用标签的约定。
## 句法和字符集
标签是一组名值对key/value pair。标签的 key 可以有两个部分:可选的前缀和标签名,通过 `/` 分隔。
* 标签名:
* 标签名部分是必须的
* 不能多于 63 个字符
* 必须由字母、数字开始和结尾
* 可以包含字母、数字、减号`-`、下划线`_`、小数点`.`
* 标签前缀:
* 标签前缀部分是可选的
* 如果指定必须是一个DNS的子域名例如project.company.com
* 不能多于 253 个字符
* 使用 `/` 和标签名分隔
如果省略标签前缀,则标签的 key 将被认为是专属于用户的。Kubernetes的系统组件例如kube-scheduler、kube-controller-manager、kube-apiserver、kubectl 或其他第三方组件向用户的Kubernetes对象添加标签时必须指定一个前缀。
`kubernetes.io/` 和 `k8s.io/` 这两个前缀是 Kubernetes 核心组件预留的。
标签的 value 必须:
* 不能多于 63 个字符
* 可以为空字符串
* 如果不为空,则
* 必须由字母、数字开始和结尾
* 可以包含字母、数字、减号`-`、下划线`_`、小数点`.`
例如下面的例子中的Pod包含两个标签 `environment: production` 和 `app:nginx`
``` yaml
apiVersion: v1
kind: Pod
metadata:
name: label-demo
labels:
environment: production
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
```
## 标签选择器
与 [name 和 UID](./names.html) 不同标签不一定是唯一的。通常来讲会有多个Kubernetes对象包含相同的标签。通过使用标签选择器label selector用户/客户端可以选择一组对象。标签选择器label selector是 Kubernetes 中最主要的分类和筛选手段。
Kubernetes api server支持两种形式的标签选择器`equality-based 基于等式的` 和 `set-based 基于集合的`。标签选择器可以包含多个条件,并使用逗号分隔,此时只有满足所有条件的 Kubernetes 对象才会被选中。
如果使用空的标签选择器或者不指定选择器,其含义由具体的 API 接口决定。
### 基于等式的选择方式
Equality- 或者 inequality-based 选择器可以使用标签的名和值来执行过滤选择。只有匹配所有条件的对象才被选中(被选中的对象可以包含未指定的标签)。可以使用三种操作符 `=`、`==`、`!=`。前两个操作符含义是一样的,都代表相等,后一个操作符代表不相等。例如:
``` sh
# 选择了标签名为 `environment` 且 标签值为 `production` 的Kubernetes对象
environment = production
# 选择了标签名为 `tier` 且标签值不等于 `frontend` 的对象,以及不包含标签 `tier` 的对象
tier != frontend
```
也可以使用逗号分隔的两个等式 `environment=production,tier!=frontend`,此时将选中所有 `environment` 为 `production` 且 `tier` 不为 `frontend` 的对象。
以 [Pod 的节点选择器](/learning/k8s-intermediate/config/assign-pod-node.html#节点选择器-nodeselector) 为例,下面的 Pod 可以被调度到包含标签 `accelerator=nvidia-tesla-p100` 的节点上:
``` yaml
apiVersion: v1
kind: Pod
metadata:
name: cuda-test
spec:
containers:
- name: cuda-test
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1
nodeSelector:
accelerator: nvidia-tesla-p100
```
### 基于集合的选择方式
Set-based 标签选择器可以根据标签名的一组值进行筛选。支持的操作符有三种:`in`、`notin`、`exists`。例如:
``` sh
# 选择所有的包含 `environment` 标签且值为 `production` 或 `qa` 的对象
environment in (production, qa)
# 选择所有的 `tier` 标签不为 `frontend` 和 `backend`的对象,或不含 `tier` 标签的对象
tier notin (frontend, backend)
# 选择所有包含 `partition` 标签的对象
partition
# 选择所有不包含 `partition` 标签的对象
!partition
```
可以组合多个选择器,用 `,` 分隔,`,` 相当于 `AND` 操作符。例如:
``` sh
# 选择包含 `partition` 标签(不检查标签值)且 `environment` 不是 `qa` 的对象
partition,environment notin (qa)
```
基于集合的选择方式是一个更宽泛的基于等式的选择方式,例如,`environment=production` 等价于 `environment in (production)``environment!=production` 等价于 `environment notin (production)`。
基于集合的选择方式可以和基于等式的选择方式可以混合使用,例如:
`partition in (customerA, customerB),environment!=qa`
## API
### 查询条件
LIST 和 WATCH 操作时,可指定标签选择器作为查询条件,以筛选指定的对象集合。两种选择方式都可以使用,但是要符合 URL 编码,例如:
* 基于等式的选择方式: `?labelSelector=environment%3Dproduction,tier%3Dfrontend`
* 基于集合的选择方式: `?labelSelector=environment+in+%28production%2Cqa%29%2Ctier+in+%28frontend%29`
两种选择方式都可以在 kubectl 的 list 和 watch 命令中使用,例如:
* 使用基于等式的选择方式
``` sh
kubectl get pods -l environment=production,tier=frontend
```
* 使用基于集合的选择方式
``` sh
kubectl get pods -l 'environment in (production),tier in (frontend)'
```
### Kubernetes对象引用
某些 Kubernetes 对象中例如Service和Deployment使用标签选择器指定一组其他类型的 Kubernetes 对象例如Pod
#### Service
Service 中通过 `spec.selector` 字段来选择一组 Pod并将服务请求转发到选中的 Pod 上。
在 yaml 或 json 文件中,标签选择器用一个 map 来定义,且支持基于等式的选择方式,例如:
``` json
"selector": {
"component" : "redis",
}
```
``` yaml
selector:
component: redis
```
上面的例子中定义的标签选择器等价于 `component=redis` 或 `component in (redis)`
#### 有些对象支持基于集合的选择方式
`Job`、`Deployment`、`ReplicaSet` 和 `DaemonSet` 同时支持基于等式的选择方式和基于集合的选择方式。例如:
``` yaml
selector:
matchLabels:
component: redis
matchExpressions:
- {key: tier, operator: In, values: [cache]}
- {key: environment, operator: NotIn, values: [dev]}
```
`matchLabels` 是一个 {key,value} 组成的 map。map 中的一个 {key,value} 条目相当于 `matchExpressions` 中的一个元素,其 `key` 为 map 的 key`operator` 为 `In` `values` 数组则只包含 `value` 一个元素。`matchExpression` 等价于基于集合的选择方式,支持的 `operator` 有 `In`、`NotIn`、`Exists` 和 `DoesNotExist`。当 `operator` 为 `In` 或 `NotIn` 时,`values` 数组不能为空。所有的选择条件都以 AND 的形式合并计算,即所有的条件都满足才可以算是匹配。
#### 引用一组节点
可以通过标签选择器将 Pod 调度到指定的节点上,请参考 [将容器组调度到指定的节点](/learning/k8s-intermediate/config/assign-pod-node.html)

View File

@ -9,6 +9,16 @@ description: 本文描述了Kuboard_v1.0.x的版本变更说明
Kuboard v1.0.x 的更新说明
## v1.0.4-beta.4
**发布日期**
2019年10月15日
**BUG 修复**
* 创建 Secret 时,如果内容包含中文,不能成功保存
## v1.0.4-beta.3
**发布日期**

View File

@ -28,7 +28,7 @@ description: Kubernetes教程_本文描述了如何获得Kuboard授权
<el-card style="height: 100%; color: #2c3e50; line-height: 1.7;">
<li>Kuboard 诞生于大型微服务项目的落地实施,在其发布之前,就已经在许多个实际项目中经受住了考验</li>
<li>Kuboard 一经发布,就获得了广泛的关注</li>
<li>Kuboard 公开发布不到两个月时间,就已经获得了 461 Github Star如图所示</li>
<li>Kuboard 公开发布不到两个月时间,就已经获得了 461 Github Star如图所示,当前 <StarCount></StarCount></li>
<li>Kuboard 社群中,已有许多的用户将 Kuboard 用于自己的生产环境</li>
</el-card>
</grid-item>