Debug初始化容器

This commit is contained in:
huanqing.shao
2019-10-24 22:04:29 +08:00
parent ba09871630
commit 05c2ab2867
13 changed files with 243 additions and 8 deletions

View File

@ -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 部署及管理,',

View File

@ -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

View 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: {}

View File

@ -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>

View File

@ -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/`

View File

@ -8,7 +8,7 @@ meta:
content: K8S教程,K8S 教程,K8S培训,Kubernetes培训
---
# Kubernetes教程K8S培训
# Kubernetes教程
<AdSenseTitle>

View File

@ -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

View File

@ -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 nameFQDN
当您创建一个 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 nameFQDN
## 并非所有对象都在名称空间里

View 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>
...
```

View 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
View File

@ -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",

View File

@ -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",