diff --git a/.vuepress/config-sidebar.js b/.vuepress/config-sidebar.js index 8ac081c..627b34a 100644 --- a/.vuepress/config-sidebar.js +++ b/.vuepress/config-sidebar.js @@ -224,13 +224,19 @@ module.exports = { title: '服务发现、负载均衡、网络', collapsable: true, children: [ - 'k8s-intermediate/service/service', - 'k8s-intermediate/service/service-details', - 'k8s-intermediate/service/service-types', - 'k8s-intermediate/service/dns', - 'k8s-intermediate/service/host-alias', - 'k8s-intermediate/service/connecting', + { + title: 'Service', + collapsable: true, + children: [ + 'k8s-intermediate/service/service', + 'k8s-intermediate/service/service-details', + 'k8s-intermediate/service/service-types', + 'k8s-intermediate/service/dns', + 'k8s-intermediate/service/connecting', + ] + }, 'k8s-intermediate/service/ingress', + 'k8s-intermediate/service/host-alias', 'k8s-intermediate/service/cni', { title: '网络策略', @@ -397,6 +403,7 @@ module.exports = { collapsable: true, children: [ 'k8s-practice/access/port-forward', + 'k8s-practice/admin/list-images', ] }, { diff --git a/learning/k8s-intermediate/service/cni.md b/learning/k8s-intermediate/service/cni.md index 57ca34f..68c99b7 100644 --- a/learning/k8s-intermediate/service/cni.md +++ b/learning/k8s-intermediate/service/cni.md @@ -11,9 +11,9 @@ meta: -本文转载自: [kubernetes网络插件对比分析(flannel、calico、weave)](https://www.toutiao.com/a6708893686517727748/) - -原文作者:残花花败柳柳 +> 本文转载自: [kubernetes网络插件对比分析(flannel、calico、weave)](https://www.toutiao.com/a6708893686517727748/) +> +> 原文作者:残花花败柳柳 diff --git a/learning/k8s-intermediate/service/connecting.md b/learning/k8s-intermediate/service/connecting.md index 678d569..fbb7896 100644 --- a/learning/k8s-intermediate/service/connecting.md +++ b/learning/k8s-intermediate/service/connecting.md @@ -7,7 +7,7 @@ meta: content: Kubernetes教程,K8S教程,Kubernetes Service,Kubernetes服务发现 --- -# Service连接应用程序 +# Example:Service连接应用程序 diff --git a/learning/k8s-practice/admin/list-images.md b/learning/k8s-practice/admin/list-images.md new file mode 100644 index 0000000..e375c00 --- /dev/null +++ b/learning/k8s-practice/admin/list-images.md @@ -0,0 +1,102 @@ +--- +vssueId: 156 +layout: LearningLayout +lessAds: false +description: Kubernetes教程_本文描述了如何使用kubectl查看集群中的容器镜像 +meta: + - name: keywords + content: Kubernetes教程,K8S教程,K8S 容器镜像,K8S培训,K8S教程 +--- + +# 查看集群中的容器镜像 + + + +> 参考文档: [List All Container Images Running in a Cluster](https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/) + +本文描述了如何使用 kubectl 查看集群中的容器镜像。 + +[[TOC]] + + + +## 前提条件 + +* 您必须有一个K8S集群 + * 可参考 [安装Kubernetes单Master节点集群](/install/install-k8s.html) + * kubectl 版本不低于 1.14,可参考 [安装kubectl](/install/install-kubectl.html) +* 在执行 kubectl 命令的机器上任意位置创建一个空白目录用于本例子的执行。本文假设后续所有命令的当前目录都是此时创建的这个目录。 + +## 查看所有名称空间总的容器 + +* 执行命令,获取所有名称空间中的所有 Pod + ``` sh + kubectl get pods --all-namespaces + ``` +* 使用 `-o jsonpath={..image}` 参数,输出结果将格式化为只包含容器镜像名字的形式。该参数将递归地查找 JSON 数据中所有 `image` 字段,例如: + ``` sh + kubectl get pods --all-namespaces -o jsonpath={..image} + ``` + * 参考 [jsonpath reference](https://kubernetes.io/docs/user-guide/jsonpath/) 了解如何使用 jsonpath + +* 使用工具 `tr`、`sort`、`uniq` 格式化输出结果 + * 使用 `tr` 将空格替换为新的行 + * 使用 `sort` 对结果排序 + * 使用 `uniq` 对镜像使用计数 + + ```sh + kubectl get pods --all-namespaces -o jsonpath="{..image}" |\ + tr -s '[[:space:]]' '\n' |\ + sort |\ + uniq -c + ``` + 此命令将递归返回所有 `image` 字段。 + +此外,也可以用 Pod 中 image 字段的绝对路径来查找容器的镜像名字,可以规避 image 字段重复出现的情况。 + + ```sh + kubectl get pods --all-namespaces -o jsonpath="{.items[*].spec.containers[*].image}" + ``` + +Jsonpath 的解析如下: +* `.items[*]`:每一个返回值 +* `.spec`: 获取 spec +* `.containers[*]`: 每一个 container +* `.image`:获取 image + +::: tip 注意 +如果通过名字查找 Pod,例如 `kubectl get pod nginx`,由于返回结果只有一个 Pod,此时,`.items[*]` 这一部分应该从 jsonpath 中移除。 +::: + +## 按Pod查找容器 + +输出结果可以通过 `rannge` 操作遍历 + +```sh +kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\ +sort +``` + +## 按Pod的label查找容器 + +使用 `-l` 参数,可以查找指定标签的 Pod,下面的例子中只查找带有 `app=nginx` 标签的 Pod: + +```sh +kubectl get pods --all-namespaces -o=jsonpath="{..image}" -l app=nginx +``` + +## 按名称空间查找容器 + +使用 `--namespace` 参数,可以查找指定名称空间下的 Pod,下面的例子只查找 `kube-system` 名称空间中的 Pod: + +``` sh +kubectl get pods --namespace kube-system -o jsonpath="{..image}" +``` + +## 使用go-template罗列容器 + +除了 jsonpath 之外,kubectl 支持使用 [go-template](https://golang.org/pkg/text/template/) 格式化输出结果: + +```sh +kubectl get pods --all-namespaces -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}" +``` diff --git a/learning/k8s-practice/lnmp/wordpress.md b/learning/k8s-practice/lnmp/wordpress.md index c7d15f9..3c96403 100644 --- a/learning/k8s-practice/lnmp/wordpress.md +++ b/learning/k8s-practice/lnmp/wordpress.md @@ -1,7 +1,7 @@ --- -# vssueId: 67 +vssueId: 156 layout: LearningLayout -lessAds: true +lessAds: false description: Kubernetes教程_本文描述了如何在K8S上部署一个WordPress和MySQL应用_并将数据存储在PersistentVolume中 meta: - name: keywords diff --git a/support/change-log/change-log-on-the-way.md b/support/change-log/change-log-on-the-way.md index 5d88bd3..2dbc386 100644 --- a/support/change-log/change-log-on-the-way.md +++ b/support/change-log/change-log-on-the-way.md @@ -1,15 +1,5 @@ Kuboard v1.0.x 的更新说明 -## v1.0.5-beta.1 - -**发布日期** - -2019年11月5日 - -**新特性** - -* HostAliases - * 清理事件 diff --git a/support/change-log/v1.0.x.md b/support/change-log/v1.0.x.md index 85b3974..6bab0d8 100644 --- a/support/change-log/v1.0.x.md +++ b/support/change-log/v1.0.x.md @@ -9,6 +9,21 @@ description: 本文描述了Kuboard_v1.0.x的版本变更说明 Kuboard v1.0.x 的更新说明 +## v1.0.5-beta.1 + +**发布日期** + +2019年11月17日 + +**新特性** + +* HostAliases +* Ingress中可以选择与workload非同名的Service + +**BUG 修复** + +* Service访问方式的提示错误 + ## v1.0.4.1 **发布日期**