Debug初始化容器
This commit is contained in:
@ -54,7 +54,7 @@ export default {
|
||||
strong: '一键离线安装',
|
||||
action: '去看看',
|
||||
url: 'http://store.lameleg.com?referrer=shaohq',
|
||||
weight: 50
|
||||
weight: 20
|
||||
},
|
||||
{
|
||||
name: '阳明的博客',
|
||||
@ -64,6 +64,14 @@ export default {
|
||||
url: 'https://www.qikqiak.com/post/promotion-51/',
|
||||
weight: 50
|
||||
},
|
||||
{
|
||||
name: '极客时间',
|
||||
description: '精要30计,让DevOps快速落地',
|
||||
strong: 'DevOps实战笔记',
|
||||
action: '去看看',
|
||||
url: 'https://time.geekbang.org/column/intro/100036601?code=0Totv3yN%2FohiumTclUF4ky4qRYs9Ecq6ZK4IdgNf88M%3D',
|
||||
weight: 30
|
||||
},
|
||||
// {
|
||||
// name: '宝塔面板',
|
||||
// description: '一键全能 Linux 部署及管理,',
|
||||
|
||||
@ -52,6 +52,14 @@ module.exports = {
|
||||
return dateFns.format(timestamp, 'YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
},
|
||||
'vuepress-plugin-code-copy': {
|
||||
successText: '已复制到剪贴板!',
|
||||
align: 'bottom',
|
||||
backgroundColor: '#FFFFFF',
|
||||
color: '#FFFFFF',
|
||||
// selector: 'div[class*="language-"] pre'
|
||||
selector: 'div[class*="language-"] pre'
|
||||
},
|
||||
// '@vuepress/pwa': {
|
||||
// serviceWorker: true,
|
||||
// // popupComponent: 'KbSWUpdatePopup',
|
||||
@ -320,6 +328,8 @@ module.exports = {
|
||||
'k8s-intermediate/workload/pod',
|
||||
'k8s-intermediate/workload/pod-lifecycle',
|
||||
'k8s-intermediate/workload/init-container',
|
||||
'k8s-intermediate/workload/init-config',
|
||||
'k8s-intermediate/workload/init-debug',
|
||||
'k8s-intermediate/workload/workload',
|
||||
{
|
||||
title: '控制器 - Deployment',
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 39 KiB |
29
.vuepress/public/statics/learning/initcontainer/config.yaml
Normal file
29
.vuepress/public/statics/learning/initcontainer/config.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: init-demo
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: workdir
|
||||
mountPath: /usr/share/nginx/html
|
||||
# These containers are run during pod initialization
|
||||
initContainers:
|
||||
- name: install
|
||||
image: busybox
|
||||
command:
|
||||
- wget
|
||||
- "-O"
|
||||
- "/work-dir/index.html"
|
||||
- https://kuboard.cn
|
||||
volumeMounts:
|
||||
- name: workdir
|
||||
mountPath: "/work-dir"
|
||||
dnsPolicy: Default
|
||||
volumes:
|
||||
- name: workdir
|
||||
emptyDir: {}
|
||||
@ -5,7 +5,7 @@
|
||||
<grid-item size="1/3" :rwd="{tablet: '1/1', compact: '1/1'}" >
|
||||
<el-card style="height: 100%; margin-top: 1rem;" shadow="none" :body-style="{padding: '0rem 1.5rem'}">
|
||||
<h4>QQ群</h4>
|
||||
<div>
|
||||
<div>一键进群
|
||||
<Qq/> 808894550
|
||||
</div>
|
||||
<p style="margin-bottom: 0; margin-top: 10px;">
|
||||
@ -18,7 +18,7 @@
|
||||
<h4>微信群</h4>
|
||||
<div>
|
||||
<div style="margin-top: 10px;">
|
||||
<span>扫二维码加微信进群聊(群主会要求您分享图片到朋友圈)</span>
|
||||
<span>微信扫码进群聊(需分享图片到朋友圈)</span>
|
||||
<p style="margin-top: 10px; margin-bottom: 0; text-align: center;">
|
||||
<!-- <img src="/images/dz.png" style="width: 150px;"></img> -->
|
||||
<img src="/images/dz2.jpeg" style="width: 150px;"></img>
|
||||
|
||||
@ -83,7 +83,7 @@ Kubernetes Dashboard 当前,只支持使用 Bearer Token登录。
|
||||
|
||||
* 执行 `kubectl proxy` 命令
|
||||
|
||||
您必须能够在自己的笔记本(工作电脑)上运行 kubectl 并访问您的集群。可参考文档 [安装Kubectl](./install/install-kubectl.html)
|
||||
您必须能够在自己的笔记本(工作电脑)上运行 kubectl 并访问您的集群。可参考文档 [安装Kubectl](./install-kubectl.html)
|
||||
|
||||
访问路径: `http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/`
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ meta:
|
||||
content: K8S教程,K8S 教程,K8S培训,Kubernetes培训
|
||||
---
|
||||
|
||||
# Kubernetes教程K8S培训
|
||||
# Kubernetes教程
|
||||
|
||||
<AdSenseTitle>
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ Resource Limits
|
||||
该结果中展示了 [Resource Quota](/learning/k8s-advanced/policy/rq.html) 和 [resource limit range](/learning/k8s-advanced/policy/lr.html)
|
||||
:::
|
||||
|
||||
* Resource quota 汇总了名称空间中使用的资源总量,并云讯集群管理员定义该名称空间最多可以使用的资源量
|
||||
* Resource quota 汇总了名称空间中使用的资源总量,并指定了集群管理员定义该名称空间最多可以使用的资源量
|
||||
* Limit range 定义了名称空间中某种具体的资源类型的最大、最小值
|
||||
|
||||
名称空间可能有两种状态(phase):
|
||||
@ -216,7 +216,7 @@ Kubernetes名称空间为集群中的 Pod、Service、Deployment 提供了一个
|
||||
|
||||
* 切换到 `development` 名称空间:
|
||||
``` sh
|
||||
kubectl config use-conetxt dev
|
||||
kubectl config use-context dev
|
||||
```
|
||||
验证
|
||||
``` sh
|
||||
|
||||
@ -80,7 +80,7 @@ kubectl config view --minify | grep namespace:
|
||||
|
||||
## 名称空间与DNS
|
||||
|
||||
当您创建一个 Service 时,Kubernetes 为其创建一个对应的 [DNS 条目](/learning/k8s-intermediate/service/dns.html)。该 DNS 记录的格式为 `<service-name>.<namespace-name>.svc.cluster.local`,也就是说,如果在容器中只使用 `<service-name>`,其DNS将解析到同名称空间下的 Service。这个特点在多环境的情况下非常有用,例如将开发环境、测试换寂静、生产环境部署在不同的名称空间下,应用程序只需要使用 `<service-name>` 即可进行服务发现,无需为不同的环境修改配置。如果您想跨名称空间访问服务,则必须使用完整的域名(fully qualified domain name,FQDN)。
|
||||
当您创建一个 Service 时,Kubernetes 为其创建一个对应的 [DNS 条目](/learning/k8s-intermediate/service/dns.html)。该 DNS 记录的格式为 `<service-name>.<namespace-name>.svc.cluster.local`,也就是说,如果在容器中只使用 `<service-name>`,其DNS将解析到同名称空间下的 Service。这个特点在多环境的情况下非常有用,例如将开发环境、测试环境、生产环境部署在不同的名称空间下,应用程序只需要使用 `<service-name>` 即可进行服务发现,无需为不同的环境修改配置。如果您想跨名称空间访问服务,则必须使用完整的域名(fully qualified domain name,FQDN)。
|
||||
|
||||
## 并非所有对象都在名称空间里
|
||||
|
||||
|
||||
75
learning/k8s-intermediate/workload/init-config.md
Normal file
75
learning/k8s-intermediate/workload/init-config.md
Normal file
@ -0,0 +1,75 @@
|
||||
---
|
||||
vssueId: 149
|
||||
layout: LearningLayout
|
||||
description: Kubernetes培训_本文描述了如何为Pod配置初始化容器InitContainer
|
||||
meta:
|
||||
- name: keywords
|
||||
content: Kubernetes教程,K8S教程,init container,初始化容器,initialize container
|
||||
---
|
||||
|
||||
# 容器组_配置初始化容器
|
||||
|
||||
|
||||
<AdSenseTitle>
|
||||
|
||||
> 参考文档: Kubernetes 官网 [Configure Pod Initialization](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/)
|
||||
|
||||
本文描述了如何为Pod配置初始化容器InitContainer。
|
||||
|
||||
</AdSenseTitle>
|
||||
|
||||
本例中,您将创建一个Pod,该Pod包含一个应用程序容器(工作容器)和一个初始化容器(Init Container)。初始化容器执行结束之后,应用程序容器(工作容器)才开始启动。
|
||||
|
||||
Pod 的配置文件如下:
|
||||
|
||||
<<< @/.vuepress/public/statics/learning/initcontainer/config.yaml
|
||||
|
||||
从配置文件可以看出,Pod 中初始化容器和应用程序共享了同一个数据卷。初始化容器将该共享数据卷挂载到 `/work-dir` 路径,应用程序容器将共享数据卷挂载到 `/usr/share/nginx/html` 路径。初始化容器执行如下命令后,就退出执行:
|
||||
|
||||
``` sh
|
||||
wget -O /work-dir/index.html https://kuboard.cn
|
||||
```
|
||||
|
||||
执行该命令时,初始化容器将结果写入了应用程序容器 nginx 服务器对应的 html 根路径下的 `index.html`。
|
||||
|
||||
* 执行命令以创建 Pod
|
||||
|
||||
``` sh
|
||||
kubectl apply -f https://kuboard.cn/statics/learning/initcontainer/config.yaml
|
||||
```
|
||||
|
||||
* 验证nginx容器已经运行
|
||||
|
||||
``` sh
|
||||
kubectl get pod init-demo
|
||||
```
|
||||
|
||||
输出结果如下所示:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
init-demo 1/1 Running 0 1m
|
||||
```
|
||||
|
||||
* 获得 nginx 容器的命令行终端:
|
||||
|
||||
``` sh
|
||||
kubectl exec -it init-demo -- /bin/bash
|
||||
```
|
||||
|
||||
在命令行终端中执行向 nginx 发送一个 GET 请求:
|
||||
|
||||
``` sh
|
||||
apt-get update
|
||||
apt-get install curl
|
||||
curl localhost
|
||||
```
|
||||
|
||||
输出结果将显示nginx根目录下的 index.html 文件(该文件由初始化容器写入到共享数据卷):
|
||||
``` html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" style="margin-right: 0px;"><head>
|
||||
<meta charset="utf-8">
|
||||
<title>Kuboard官网_Kubernetes教程_管理界面</title>
|
||||
...
|
||||
```
|
||||
106
learning/k8s-intermediate/workload/init-debug.md
Normal file
106
learning/k8s-intermediate/workload/init-debug.md
Normal file
@ -0,0 +1,106 @@
|
||||
---
|
||||
vssueId: 149
|
||||
layout: LearningLayout
|
||||
description: Kubernetes教程_本文描述了如何诊断初始化容器InitContainer在执行过程中的问题_本文中的命令行使用<pod-name>来指代Pod的名称_使用<init-container-1>和<init-container-2>来指代初始化容器的名称
|
||||
meta:
|
||||
- name: keywords
|
||||
content: Kubernetes教程,K8S教程,init container,初始化容器,initialize container
|
||||
---
|
||||
|
||||
# 容器组_Debug初始化容器
|
||||
|
||||
|
||||
<AdSenseTitle>
|
||||
|
||||
> 参考文档: Kubernetes 官网 [Debug Init Containers](https://kubernetes.io/docs/tasks/debug-application-cluster/debug-init-containers/)
|
||||
|
||||
本文描述了如何诊断初始化容器InitContainer在执行过程中的问题_本文中的命令行使用 `<pod-name>` 来指代Pod的名称_使用 `<init-container-1>` 和 `<init-container-2>` 来指代初始化容器的名称。
|
||||
|
||||
本文假设您已经完成了 [容器组_配置初始化容器](./init-config.html)
|
||||
|
||||
[[TOC]]
|
||||
|
||||
</AdSenseTitle>
|
||||
|
||||
## 检查初始化容器的状态
|
||||
|
||||
执行命令,查看 Pod 的状态:
|
||||
|
||||
``` sh
|
||||
kubectl get pod <pod-name>
|
||||
```
|
||||
|
||||
例如,状态如果是 `Init:1/2`,则表明了两个初始化容器当中的一个已经成功执行:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
<pod-name> 0/1 Init:1/2 0 7s
|
||||
```
|
||||
|
||||
## 查看初始化容器的详情
|
||||
|
||||
查看初始化容器的更多信息:
|
||||
|
||||
``` sh
|
||||
kubectl describe pod <pod-name>
|
||||
```
|
||||
|
||||
假设 Pod 包含两个初始化容器,显示结果可能如下所示:
|
||||
|
||||
```
|
||||
Init Containers:
|
||||
<init-container-1>:
|
||||
Container ID: ...
|
||||
...
|
||||
State: Terminated
|
||||
Reason: Completed
|
||||
Exit Code: 0
|
||||
Started: ...
|
||||
Finished: ...
|
||||
Ready: True
|
||||
Restart Count: 0
|
||||
...
|
||||
<init-container-2>:
|
||||
Container ID: ...
|
||||
...
|
||||
State: Waiting
|
||||
Reason: CrashLoopBackOff
|
||||
Last State: Terminated
|
||||
Reason: Error
|
||||
Exit Code: 1
|
||||
Started: ...
|
||||
Finished: ...
|
||||
Ready: False
|
||||
Restart Count: 3
|
||||
...
|
||||
```
|
||||
|
||||
也可以直接读取 Pod 的 `status.initContainerStatuses` 字段,命令行如下所示:
|
||||
|
||||
``` sh
|
||||
kubectl get pod <pod-name> --template '{{.status.initContainerStatuses}}'
|
||||
```
|
||||
|
||||
该命令将以 JSON 格式返回信息
|
||||
|
||||
|
||||
## 查看初始化容器的日志
|
||||
|
||||
执行命令查看初始化容器的日志:
|
||||
|
||||
``` sh
|
||||
kubectl logs <pod-name> -c <init-container-1>
|
||||
```
|
||||
|
||||
## 理解 Pod 状态
|
||||
|
||||
如果 Pod 的状态以 `Init:` 开头,表示该 Pod 正在执行初始化容器。下表描述了 Debug 初始化容器的过程中,一些可能出现的 Pod 状态:
|
||||
|
||||
| 状态 | 描述 |
|
||||
| ------------------------------ | ---------------------------------------------------------- |
|
||||
| `Init:N/M` | Pod 中包含 M 个初始化容器,其中 N 个初始化容器已经成功执行 |
|
||||
| `Init:Error` | Pod 中有一个初始化容器执行失败 |
|
||||
| `Init:CrashLoopBackOff` | Pod 中有一个初始化容器反复执行失败 |
|
||||
| `Pending` | Pod 还未开始执行初始化容器 |
|
||||
| `PodInitializing` or `Running` | Pod 已经完成初始化容器的执行 |
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@ -12196,6 +12196,12 @@
|
||||
"integrity": "sha1-5QQhcPBaWFxKOPh24B/0cGzYL74=",
|
||||
"dev": true
|
||||
},
|
||||
"vuepress-plugin-code-copy": {
|
||||
"version": "1.0.4-alpha",
|
||||
"resolved": "https://registry.npm.taobao.org/vuepress-plugin-code-copy/download/vuepress-plugin-code-copy-1.0.4-alpha.tgz",
|
||||
"integrity": "sha1-k/0CyNR93lPmP94RL2ORQgNHg18=",
|
||||
"dev": true
|
||||
},
|
||||
"vuepress-plugin-code-switcher": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/vuepress-plugin-code-switcher/download/vuepress-plugin-code-switcher-1.0.0.tgz",
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
"babel-plugin-component": "^1.1.1",
|
||||
"date-fns": "^1.30.1",
|
||||
"vuepress-plugin-baidu-autopush": "^1.0.1",
|
||||
"vuepress-plugin-code-copy": "^1.0.4-alpha",
|
||||
"vuepress-plugin-code-switcher": "^1.0.0",
|
||||
"vuepress-plugin-reading-progress": "^1.0.7",
|
||||
"vuepress-plugin-seo": "^0.1.2",
|
||||
|
||||
Reference in New Issue
Block a user