Skip to content

Commit 0b9ab90

Browse files
添加docker 和 ingress相关
1 parent e43aaad commit 0b9ab90

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

containerd/docker.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,29 @@ CMD ["flask", "run", "--host=0.0.0.0"]
11541154
11551155
docker使用虚拟网桥技术实现宿主机和docker容器之间的互联互通。
11561156
1157+
### 使用已有的多个基础镜像制作新的镜像
1158+
1159+
以下dockerfile将 2.4.2内容中的nginx-ingress,复制到5.1.0版本的镜像中,并生成一个新的镜像,新的镜像以5.1.0为基础镜像。
1160+
```dockerfile
1161+
# syntax=docker/dockerfile:1.4
1162+
1163+
# 阶段1:使用 nginx:2.4.2 作为源镜像
1164+
FROM nginx/nginx-ingress:2.4.2 AS source
1165+
1166+
# 阶段2:使用目标基础镜像
1167+
FROM nginx/nginx-ingress:5.1.0 AS target
1168+
1169+
# 从源镜像复制 nginx 二进制文件到目标镜像
1170+
COPY --from=source /nginx-ingress /
1171+
1172+
# 可选:复制 nginx 配置文件目录(如果需要)
1173+
# COPY --from=source /etc/nginx /etc/nginx
1174+
1175+
# 标签(可选)
1176+
LABEL org.example.nginx.version="2.4.2 extracted"
1177+
```
1178+
1179+
11571180
### 实战
11581181
11591182
因为平时使用的 go 语言开发,所以使用 go 语言开发一个简单的 web 服务,并使用 Dockerfile 构建镜像。

go/go.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,27 @@ func main() {
10141014
}
10151015
```
10161016

1017+
## net 网络
10171018

1019+
### go程序解析DNS失败但是curl解析正常
1020+
DNS解析时go使用的可以是系统自带的也可以是go本身的,当系统中的DNS解析有问题(特别是裁剪之后的镜像),可以开启go的自带DNS解析
1021+
1022+
```bash
1023+
GODEBUG=netdns=go ./myapp
1024+
```
1025+
或者
1026+
```go
1027+
type Resolver struct {
1028+
// PreferGo controls whether Go's built-in DNS resolver is preferred // on platforms where it's available. It is equivalent to setting // GODEBUG=netdns=go, but scoped to just this resolver.
1029+
PreferGo bool
1030+
...
1031+
}
1032+
1033+
func init() {
1034+
// 设置 GODEBUG 环境变量以强制使用 Go 自带的 DNS 解析器
1035+
os.Setenv("GODEBUG", "netdns=go")
1036+
}
1037+
```
10181038

10191039

10201040

144 KB
Loading
61.5 KB
Loading

k8s/ingress.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11

22

3-
4-
5-
6-
7-
8-
93
## nginx ingress
104
### nginx ingress redirect
115
```yaml
@@ -245,4 +239,39 @@ spec:
245239
name: example-service
246240
port:
247241
number: 80
248-
```
242+
```
243+
244+
245+
## NGINX Ingress Controller pod
246+
![[Pasted image 20250805111001.png]]
247+
248+
249+
### 处理新的ingress资源
250+
251+
![[Pasted image 20250805111221.png]]
252+
253+
1. _User_ creates a new Ingress resource.
254+
_用户_ 创建一个新的 Ingress 资源。
255+
2. The NGINX Ingress Controller process has a _Cache_ of the resources in the cluster. The _Cache_ includes only the resources NGINX Ingress Controller is concerned with such as Ingresses. The _Cache_ stays in sync with the Kubernetes API by [watching for changes to the resources](https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes).
256+
NGINX Ingress Controller 进程拥有集群资源的_缓存_ 。该_缓存_仅包含 NGINX Ingress Controller 关注的资源,例如 Ingress。该_缓存_通过[监视资源的变化](https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes)与 Kubernetes API 保持同步。
257+
3. Once the _Cache_ has the new Ingress resource, it notifies the _Control Loop_ about the changed resource.
258+
一旦_缓存_有了新的入口资源,它就会通知_控制循环_有关更改的资源。
259+
4. The _Control Loop_ gets the latest version of the Ingress resource from the _Cache_. Since the Ingress resource references other resources, such as TLS Secrets, the _Control loop_ gets the latest versions of those referenced resources as well.
260+
_控制循环_从 _Cache_ 获取 Ingress 资源的最新版本。由于 Ingress 资源引用了其他资源(例如 TLS Secrets),因此_控制循环_也会获取这些引用资源的最新版本。
261+
5. The _Control Loop_ generates TLS certificates and keys from the TLS Secrets and writes them to the filesystem.
262+
_控制循环_ 从 TLS 机密生成 TLS 证书和密钥,并将它们写入文件系统。
263+
6. The _Control Loop_ generates and writes the NGINX _configuration files_, which correspond to the Ingress resource, and writes them to the filesystem.
264+
_控制循环_ 生成并写入与 Ingress 资源对应的 NGINX  _配置文件_  ,并将其写入文件系统。
265+
7. The _Control Loop_ reloads _NGINX_ and waits for _NGINX_ to successfully reload. As part of the reload:
266+
_控制循环_ 重新加载  _NGINX_ ,并等待 _NGINX_ 成功重新加载。重新加载过程中:
267+
1. _NGINX_ reads the _TLS certs and keys_.
268+
_NGINX_ 读取 _TLS 证书和密钥_ 。
269+
2. _NGINX_ reads the _configuration files_.
270+
_NGINX_ 读取_配置文件_ 。
271+
8. The _Control Loop_ emits an event for the Ingress resource and updates its status. If the reload fails, the event includes the error message.
272+
_控制循环_ 会为 Ingress 资源发出事件并更新其状态。如果重新加载失败,该事件会包含错误消息。
273+
274+
### NGINX Ingress Controller 是一个 Kubernetes 控制器
275+
276+
NGINX Ingress Controller 持续处理集群中的新增资源和现有资源的变更。因此,NGINX 配置始终与集群中的资源保持同步更新。
277+
NGINX Ingress Controller 是 [Kubernetes 控制器](https://kubernetes.io/docs/concepts/architecture/controller/)的一个示例:NGINX Ingress Controller 运行一个控制循环,确保 NGINX 根据所需状态(Ingress 和其他资源)进行配置。

0 commit comments

Comments
 (0)