This commit is contained in:
@@ -22,10 +22,18 @@
|
||||
|
||||
**更多参数**
|
||||
|
||||
- `--hosts-dir "/etc/containerd/certs.d"`:指定了包含镜像仓库证书的目录的路径。
|
||||
```bash
|
||||
ctr --debug=true i pull --hosts-dir=/etc/containerd/certs.d docker.io/library/nginx:latest
|
||||
```
|
||||
|
||||
- `-k`:忽略 TLS 验证过程中的证书错误。
|
||||
- `--plain-http=true`:此选项指明在拉取镜像时使用未加密的 HTTP 协议,而不是加密的 HTTPS。
|
||||
| 参数部分 | 说明 | 详细解释 |
|
||||
| :-------------------------------------: | :--: | :----------------------------------------------------------: |
|
||||
| **--debug=true** | | - 启用详细日志输出 - 显示执行过程中的详细信息 - 便于故障排查 |
|
||||
| **i** | | `images` 的缩写,表示进行镜像相关操作 |
|
||||
| **pull** | | 拉取(下载)镜像到本地 |
|
||||
| **--hosts-dir=/etc/containerd/certs.d** | | - 指定证书和注册表配置目录 - 用于配置私有注册表或镜像仓库的认证信息 - 可以覆盖默认的 registry 配置 |
|
||||
| -k | | 忽略 TLS 验证过程中的证书错误 |
|
||||
| --plain-http=true | | 此选项指明在拉取镜像时使用未加密的 HTTP 协议,而不是加密的 HTTPS |
|
||||
|
||||
- 推送镜像
|
||||
|
||||
@@ -33,6 +41,4 @@
|
||||
ctr -n k8s.io image push -u <账户>:<密码> docker.io/library/nginx:latest
|
||||
```
|
||||
|
||||
**更多参数**
|
||||
|
||||
- `--plain-http=true`:此选项指明在拉取镜像时使用未加密的 HTTP 协议,而不是加密的 HTTPS。
|
||||
|
||||
@@ -1,6 +1,36 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Docker镜像批量打包
|
||||
# Docker镜像打包
|
||||
|
||||
## 默认打包
|
||||
|
||||
1. 打包
|
||||
|
||||
```bash
|
||||
docker save -o image.tar nginx:latest
|
||||
```
|
||||
|
||||
2. 导入
|
||||
|
||||
```bash
|
||||
docker load -i image.tar
|
||||
```
|
||||
|
||||
## 打包并压缩
|
||||
|
||||
1. 打包并压缩
|
||||
|
||||
```bash
|
||||
docker save nginx:latest | gzip -c > image.tar.gz
|
||||
```
|
||||
|
||||
2. 解压并导入
|
||||
|
||||
```bash
|
||||
gunzip -c image.tar.gz | docker load
|
||||
```
|
||||
|
||||
## 批量打包
|
||||
|
||||
- 第一种
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
net.bridge.bridge-nf-call-ip6tables = 1
|
||||
net.bridge.bridge-nf-call-iptables = 1
|
||||
net.ipv6.conf.all.disable_ipv6 = 1
|
||||
net.ipv6.conf.default.disable_ipv6 = 1
|
||||
net.ipv4.ip_forward = 1
|
||||
vm.swappiness = 0
|
||||
vm.swappiness = 0
|
||||
|
||||
67
File/Yaml/ingress-values-hostnetwork.yaml
Normal file
67
File/Yaml/ingress-values-hostnetwork.yaml
Normal file
@@ -0,0 +1,67 @@
|
||||
controller:
|
||||
# 开启监控
|
||||
metrics:
|
||||
enabled: true
|
||||
serviceMonitor:
|
||||
enabled: false
|
||||
|
||||
# 配置镜像加速
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# 使用主机网络时,利用 Kubernetes 集群内的 DNS 解析服务
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
|
||||
# 使用本地网络
|
||||
hostNetwork: true
|
||||
|
||||
# Pod 使用 DaemonSet 方式运行 Deployment 或 DaemonSet
|
||||
kind: DaemonSet
|
||||
|
||||
# 只允许调度到具有 ingress="true" 的节点上,[ kubectl label node xxx ingress="true" ]
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
ingress: "true"
|
||||
|
||||
# 禁用后状态字段会报告 Ingress 控制器 Pod 所在节点的 IP 地址或节点列表的 IP 地址
|
||||
publishService:
|
||||
enabled: false
|
||||
|
||||
# 启用 Kubernetes Service
|
||||
service:
|
||||
enabled: false
|
||||
|
||||
# 配置镜像加速
|
||||
admissionWebhooks:
|
||||
patch:
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# 设置为集群默认 ingress 控制器
|
||||
ingressClassResource:
|
||||
default: true
|
||||
|
||||
# 配置资源限制
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 1Gi
|
||||
|
||||
# 配置 Pod 安全上下文
|
||||
podSecurityContext:
|
||||
fsGroup: 101
|
||||
runAsUser: 101
|
||||
|
||||
# 配置安全上下文
|
||||
containerSecurityContext:
|
||||
allowPrivilegeEscalation: false # 禁止特权提升
|
||||
capabilities:
|
||||
add: ["NET_BIND_SERVICE"]
|
||||
drop:
|
||||
- ALL # 去除所有能力
|
||||
runAsNonRoot: true # 以非 root 用户运行
|
||||
seccompProfile:
|
||||
type: RuntimeDefault # 启用默认系统调用过滤
|
||||
81
File/Yaml/ingress-values-loadbalancer.yaml
Normal file
81
File/Yaml/ingress-values-loadbalancer.yaml
Normal file
@@ -0,0 +1,81 @@
|
||||
# 未完成的 YAML 配置文件片段
|
||||
controller:
|
||||
# 开启监控
|
||||
metrics:
|
||||
enabled: true
|
||||
serviceMonitor:
|
||||
enabled: false
|
||||
|
||||
# 配置镜像加速
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# Pod 使用 DaemonSet 方式运行 Deployment 或 DaemonSet
|
||||
kind: Deployment
|
||||
# 副本数
|
||||
replicaCount: 2
|
||||
|
||||
# 只允许调度到具有 ingress="true" 的节点上,[ kubectl label node xxx ingress="true" ]
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
ingress: "true"
|
||||
|
||||
# 禁用后状态字段会报告 Ingress 控制器 Pod 所在节点的 IP 地址或节点列表的 IP 地址
|
||||
publishService:
|
||||
enabled: false
|
||||
|
||||
# 配置镜像加速
|
||||
admissionWebhooks:
|
||||
patch:
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# 设置为集群默认 ingress 控制器
|
||||
ingressClassResource:
|
||||
default: true
|
||||
|
||||
# 配置资源限制
|
||||
resources:
|
||||
requests:
|
||||
cpu: 200m
|
||||
memory: 256Mi
|
||||
limits:
|
||||
cpu: 1000m
|
||||
memory: 1Gi
|
||||
|
||||
# 配置 Pod 安全上下文
|
||||
podSecurityContext:
|
||||
fsGroup: 101
|
||||
runAsUser: 101
|
||||
|
||||
# 配置安全上下文
|
||||
containerSecurityContext:
|
||||
allowPrivilegeEscalation: false # 禁止特权提升
|
||||
capabilities:
|
||||
add: ["NET_BIND_SERVICE"]
|
||||
drop:
|
||||
- ALL # 去除所有能力
|
||||
runAsNonRoot: true # 以非 root 用户运行
|
||||
seccompProfile:
|
||||
type: RuntimeDefault # 启用默认系统调用过滤
|
||||
|
||||
service:
|
||||
type: LoadBalancer
|
||||
# 在这里指定你的浮动 IP
|
||||
loadBalancerIP: ""
|
||||
externalIPs:
|
||||
- ""
|
||||
# 根据你的环境,可能不需要额外的注解,或者可能需要设置特定的注解
|
||||
annotations:
|
||||
# 如果你的环境需要,可以添加以下注解(例如,使用 MetalLB)
|
||||
# metallb.universe.tf/address-pool: default
|
||||
# 或者,如果你使用 keepalived,可能需要以下注解来避免外部负载均衡器提供商尝试分配 IP
|
||||
# 例如,在 OpenStack 中,你可以指定使用 keepalived 的 IP
|
||||
# 注意:具体注解取决于你的环境和云提供商集成,如果没有特定的集成,可能不需要注解。
|
||||
# 对于裸机 keepalived,通常只需要指定 loadBalancerIP 即可。
|
||||
|
||||
# 其他服务配置,如端口
|
||||
ports:
|
||||
http: 80
|
||||
https: 443
|
||||
externalTrafficPolicy: Local
|
||||
33
File/Yaml/istio-config.yaml
Normal file
33
File/Yaml/istio-config.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
apiVersion: install.istio.io/v1alpha1
|
||||
kind: IstioOperator
|
||||
metadata:
|
||||
namespace: istio-system
|
||||
spec:
|
||||
hub: docker.io/istio
|
||||
tag: 1.28.1
|
||||
|
||||
components:
|
||||
base:
|
||||
enabled: true # Istio 基础组件
|
||||
pilot:
|
||||
enabled: true # Istio 控制平面(Istiod)
|
||||
# 进出口流量启用
|
||||
ingressGateways:
|
||||
- name: istio-ingressgateway
|
||||
enabled: true
|
||||
egressGateways:
|
||||
- name: istio-egressgateway
|
||||
enabled: false
|
||||
|
||||
# Most default values come from the helm chart's values.yaml
|
||||
# Below are the things that differ
|
||||
values:
|
||||
defaultRevision: "" # 控制 sidecar 注入的默认版本
|
||||
global:
|
||||
istioNamespace: istio-system # Istio 安装的命名空间
|
||||
configValidation: true # 启用配置验证
|
||||
gateways:
|
||||
istio-ingressgateway: {}
|
||||
istio-egressgateway: {}
|
||||
ztunnel:
|
||||
resourceName: ztunnel # 为 Ztunnel DaemonSet 指定名称
|
||||
@@ -18,58 +18,13 @@
|
||||
helm repo update
|
||||
```
|
||||
|
||||
2. 编写模版文件
|
||||
2. 下载模版文件
|
||||
|
||||
```bash
|
||||
vi ingress-values.yaml
|
||||
wget https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/ingress-values-hostnetwork.yaml
|
||||
```
|
||||
|
||||
内容如下
|
||||
|
||||
```yaml
|
||||
controller:
|
||||
# 开启监控
|
||||
metrics:
|
||||
enabled: true
|
||||
serviceMonitor:
|
||||
enabled: true
|
||||
|
||||
# 配置镜像加速
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# 使用主机网络时,利用 Kubernetes 集群内的 DNS 解析服务
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
|
||||
# 使用本地网络
|
||||
hostNetwork: true
|
||||
|
||||
# Pod 使用 DaemonSet 方式运行
|
||||
kind: DaemonSet
|
||||
|
||||
# 只允许调度到具有 ingress="true" 的节点上,[ kubectl label node xxx ingress="true" ]
|
||||
nodeSelector:
|
||||
kubernetes.io/os: linux
|
||||
ingress: "true"
|
||||
|
||||
# 禁用后状态字段会报告 Ingress 控制器 Pod 所在节点的 IP 地址或节点列表的 IP 地址
|
||||
publishService:
|
||||
enabled: false
|
||||
|
||||
# 启用 Kubernetes Service
|
||||
service:
|
||||
enabled: false
|
||||
|
||||
# 配置镜像加速
|
||||
admissionWebhooks:
|
||||
patch:
|
||||
image:
|
||||
registry: k8s.mirror.nju.edu.cn
|
||||
|
||||
# 设置为集群默认 ingress 控制器
|
||||
ingressClassResource:
|
||||
default: true
|
||||
```
|
||||
**修改参数并保存**
|
||||
|
||||
3. 配置节点标签
|
||||
|
||||
@@ -82,7 +37,7 @@
|
||||
```bash
|
||||
helm install ingress-nginx \
|
||||
ingress-nginx/ingress-nginx \
|
||||
-f ingress-values.yaml
|
||||
-f ingress-values-hostnetwork.yaml
|
||||
```
|
||||
|
||||
## 卸载
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
|
||||
## 准备工作
|
||||
|
||||
- Nginx Deployment
|
||||
1. 部署 Nginx 资源
|
||||
|
||||
- Nginx Service:
|
||||
```yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment.yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-svc.yaml
|
||||
```
|
||||
|
||||
Name: nginx-service
|
||||
2. 查看部署情况
|
||||
|
||||
Port: 80
|
||||
```bash
|
||||
kubectl get deploy,svc
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
@@ -22,40 +27,70 @@
|
||||
|
||||
2. 创建 Ingress 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx-ingress
|
||||
namespace: default
|
||||
annotations:
|
||||
# 不限制文件上传大小 或 选择其他参数
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "0"
|
||||
labels:
|
||||
- HTTP
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx-ingress
|
||||
spec:
|
||||
rules:
|
||||
# 对外域名
|
||||
- host: nginx.example.com
|
||||
namespace: default
|
||||
annotations:
|
||||
# 不限制文件上传大小 或 选择其他参数
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "0"
|
||||
labels:
|
||||
name: nginx-ingress
|
||||
spec:
|
||||
ingressClassName: nginx # 通过 kubectl get ingressclass 查看
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- backend:
|
||||
service:
|
||||
name: nginx-service # Nginx Serice 名称
|
||||
port:
|
||||
number: 80 # Nginx 端口
|
||||
path: /
|
||||
pathType: Prefix
|
||||
EOF
|
||||
```
|
||||
|
||||
- HTTPS
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: nginx-ingress
|
||||
namespace: default
|
||||
annotations:
|
||||
# 不限制文件上传大小 或 选择其他参数
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "0"
|
||||
labels:
|
||||
name: nginx-ingress
|
||||
spec:
|
||||
ingressClassName: nginx # 通过 kubectl get ingressclass 查看
|
||||
rules:
|
||||
- host: nginx.example.com # 修改为自己的对外域名
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
# Nginx Serice 名称
|
||||
name: nginx-service
|
||||
port:
|
||||
# Nginx 端口
|
||||
number: 80
|
||||
path: /
|
||||
# 对外域名证书配置
|
||||
tls:
|
||||
- hosts:
|
||||
- nginx.example.com
|
||||
secretName: nginx-tls
|
||||
EOF
|
||||
```
|
||||
- backend:
|
||||
service:
|
||||
name: nginx-service # Nginx Serice 名称
|
||||
port:
|
||||
number: 80 # Nginx 端口
|
||||
path: /
|
||||
pathType: Prefix
|
||||
|
||||
# 对外域名证书配置
|
||||
tls:
|
||||
- hosts:
|
||||
- nginx.example.com
|
||||
secretName: nginx-tls
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 访问域名
|
||||
|
||||
|
||||
@@ -61,17 +61,18 @@
|
||||
name: nginx-ingress-1
|
||||
namespace: default
|
||||
spec:
|
||||
ingressClassName: nginx # 通过 kubectl get ingressclass 查看
|
||||
rules:
|
||||
- host: example.com # 替换为你的域名
|
||||
- host: example.com # 修改为自己的对外域名
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
- backend:
|
||||
service:
|
||||
name: nginx-deployment-service-1
|
||||
name: nginx-deployment-service-1 # Nginx Serice 名称
|
||||
port:
|
||||
number: 80
|
||||
number: 80 # Nginx 端口
|
||||
path: /
|
||||
pathType: Prefix
|
||||
tls:
|
||||
- hosts:
|
||||
- example.com # 替换为你的域名
|
||||
@@ -87,17 +88,18 @@
|
||||
nginx.ingress.kubernetes.io/canary: "true"
|
||||
nginx.ingress.kubernetes.io/canary-weight: "10" # 10%流量到金丝雀
|
||||
spec:
|
||||
ingressClassName: nginx # 通过 kubectl get ingressclass 查看
|
||||
rules:
|
||||
- host: example.com # 替换为你的域名
|
||||
- host: example.com # 修改为自己的对外域名
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
- backend:
|
||||
service:
|
||||
name: nginx-deployment-service-2
|
||||
name: nginx-deployment-service-2 # Nginx Serice 名称
|
||||
port:
|
||||
number: 80
|
||||
number: 80 # Nginx 端口
|
||||
path: /
|
||||
pathType: Prefix
|
||||
tls:
|
||||
- hosts:
|
||||
- example.com # 替换为你的域名
|
||||
|
||||
104
网关/Istio/Istio重定向HTTP为HTTPS.md
Normal file
104
网关/Istio/Istio重定向HTTP为HTTPS.md
Normal file
@@ -0,0 +1,104 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# Istio重定向HTTP为HTTPS
|
||||
|
||||
## 部署基础服务
|
||||
|
||||
1. 部署 Nginx 资源
|
||||
|
||||
```yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment.yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-svc.yaml
|
||||
```
|
||||
|
||||
2. 查看部署情况
|
||||
|
||||
```bash
|
||||
kubectl get deploy,svc
|
||||
```
|
||||
|
||||
## 配置 Istio 对外访问
|
||||
|
||||
1. 部署 Nginx Gateway 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: nginx-gateway
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway
|
||||
servers:
|
||||
- port:
|
||||
number: 443
|
||||
name: https
|
||||
protocol: HTTPS
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
tls:
|
||||
mode: SIMPLE
|
||||
credentialName: example-tls # 替换为你的证书,这个 secret 必须在 istio-system 命名空间
|
||||
- port:
|
||||
number: 80
|
||||
name: http
|
||||
protocol: HTTP
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
EOF
|
||||
```
|
||||
|
||||
2. 部署 Nginx VirtualService 资源
|
||||
|
||||
```yaml
|
||||
http:
|
||||
- name: http-redirect
|
||||
match:
|
||||
- port: 80
|
||||
redirect:
|
||||
port: 443
|
||||
scheme: https
|
||||
- name: https-route
|
||||
match:
|
||||
- port: 443
|
||||
route:
|
||||
- destination:
|
||||
host: nginx-service.default.svc.cluster.local # 完整的服务 FQDN
|
||||
port:
|
||||
number: 80
|
||||
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- name: https-route
|
||||
match:
|
||||
- uri:
|
||||
prefix: /
|
||||
port: 443
|
||||
route:
|
||||
- destination:
|
||||
host: nginx-service.default.svc.cluster.local
|
||||
port:
|
||||
number: 80
|
||||
- name: http-redirect
|
||||
match:
|
||||
- port: 80
|
||||
redirect:
|
||||
port: 443
|
||||
scheme: https
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 访问 HTTP 实现自动跳转到 HTTPS
|
||||
|
||||
144
网关/Istio/使用Istio开启对外访问.md
Normal file
144
网关/Istio/使用Istio开启对外访问.md
Normal file
@@ -0,0 +1,144 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 使用Istio开启对外访问
|
||||
|
||||
## Istio开启对外访问
|
||||
|
||||
### 部署基础服务
|
||||
|
||||
1. 部署 Nginx 资源
|
||||
|
||||
```yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment.yaml
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-svc.yaml
|
||||
```
|
||||
|
||||
2. 查看部署情况
|
||||
|
||||
```bash
|
||||
kubectl get deploy,svc
|
||||
```
|
||||
|
||||
### 配置 Istio 对外访问
|
||||
|
||||
1. 部署 Nginx Gateway 资源
|
||||
|
||||
- HTTP
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: nginx-gateway
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway
|
||||
servers:
|
||||
- port:
|
||||
number: 80
|
||||
name: http
|
||||
protocol: HTTP
|
||||
hosts:
|
||||
- '*'
|
||||
EOF
|
||||
```
|
||||
|
||||
- HTTPS
|
||||
|
||||
1. 创建证书 Secret 资源
|
||||
|
||||
```bash
|
||||
kubectl create secret tls demo-tls --cert=server.crt --key=server.key -n istio-system
|
||||
```
|
||||
|
||||
2. 创建 Gateway 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: nginx-gateway
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway
|
||||
servers:
|
||||
- port:
|
||||
number: 443
|
||||
name: https
|
||||
protocol: HTTPS
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
tls:
|
||||
mode: SIMPLE
|
||||
credentialName: example-tls # 替换为你的证书,这个 secret 必须在 istio-system 命名空间
|
||||
EOF
|
||||
```
|
||||
|
||||
2. 部署 Nginx VirtualService 资源
|
||||
|
||||
- HTTP
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- '*'
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- match:
|
||||
- uri:
|
||||
prefix: /
|
||||
port: 80
|
||||
route:
|
||||
- destination:
|
||||
host: nginx-service.default.svc.cluster.local
|
||||
port:
|
||||
number: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
- HTTPS
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- match:
|
||||
- uri:
|
||||
prefix: /
|
||||
port: 443
|
||||
route:
|
||||
- destination:
|
||||
host: nginx-service.default.svc.cluster.local
|
||||
port:
|
||||
number: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 访问测试
|
||||
|
||||
```bash
|
||||
kubectl get svc istio-ingressgateway -n istio-system
|
||||
```
|
||||
|
||||
通过 `域名` 或 `IP:80` 访问
|
||||
|
||||
145
网关/Istio/官方Istio使用示例.md
Normal file
145
网关/Istio/官方Istio使用示例.md
Normal file
@@ -0,0 +1,145 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 官方Istio使用示例
|
||||
|
||||
[Bookinfo 应用](https://istio.io/latest/zh/docs/examples/bookinfo/)
|
||||
|
||||
## 前提条件
|
||||
|
||||
如果您还没有开始,请遵循 [Istio安装和使用](https://gitee.com/offends/Kubernetes/blob/main/%E7%BD%91%E5%85%B3/Istio/Istio%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8.md) 完成 Istio 的部署工作。
|
||||
|
||||
本文使用 Istio 官方推荐的 Gateway API 部署举例。
|
||||
|
||||
## 部署 Bookinfo
|
||||
|
||||
<img src="https://istio.io/latest/zh/docs/examples/bookinfo/withistio.svg" style="zoom:100%;" />
|
||||
|
||||
1. 进入示例目录
|
||||
|
||||
```bash
|
||||
cd istio-1.28.1
|
||||
```
|
||||
|
||||
2. 部署应用
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
|
||||
```
|
||||
|
||||
3. 要确认 Bookinfo 应用正在运行,请从某个 Pod 中(例如从 `ratings` 中)用 `curl` 命令对此应用发送一条请求
|
||||
|
||||
```bash
|
||||
kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
|
||||
```
|
||||
|
||||
结果输出 `<title>Simple Bookstore App</title>` 即代表运行成功。
|
||||
|
||||
4. 对外开放应用
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/gateway-api/bookinfo-gateway.yaml
|
||||
```
|
||||
|
||||
5. 通过注解网关将服务类型更改为 `NodePort`
|
||||
|
||||
```bash
|
||||
kubectl annotate gateway bookinfo-gateway networking.istio.io/service-type=NodePort --namespace=default
|
||||
```
|
||||
|
||||
6. 检查网关的状态
|
||||
|
||||
```bash
|
||||
kubectl get gateway
|
||||
```
|
||||
|
||||
7. 查看 NodePort 对外端口
|
||||
|
||||
```bash
|
||||
kubectl get svc bookinfo-gateway-istio
|
||||
```
|
||||
|
||||
8. 浏览器访问
|
||||
|
||||
```bash
|
||||
http://$ip:30000/productpage
|
||||
```
|
||||
|
||||
刷新页面,应该会看到书评和评分发生变化, 因为请求分布在 `reviews` 服务的不同版本上
|
||||
|
||||
## 使用 Kiali 仪表板
|
||||
|
||||
1. 安装 Kiali 仪表板
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/addons/prometheus.yaml
|
||||
kubectl apply -f samples/addons/kiali.yaml
|
||||
```
|
||||
|
||||
2. 修改对外访问模式为 NodePort
|
||||
|
||||
```bash
|
||||
kubectl patch svc kiali -n istio-system -p '{"spec":{"type":"NodePort"}}'
|
||||
```
|
||||
|
||||
3. 查看 NodePort 对外端口
|
||||
|
||||
```bash
|
||||
kubectl get svc kiali -n istio-system
|
||||
```
|
||||
|
||||
4. 浏览器访问
|
||||
|
||||
```bash
|
||||
http://$ip:30001/kiali
|
||||
```
|
||||
|
||||
5. 刷新页面并查看拓扑图
|
||||
|
||||
## 使用 Istio 实现灰度发布
|
||||
|
||||
[官方文档](https://istio.io/latest/zh/docs/tasks/traffic-management/traffic-shifting/#apply-weight-based-routing)
|
||||
|
||||
1. 定义服务可用版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/platform/kube/bookinfo-versions.yaml
|
||||
```
|
||||
|
||||
2. 首先,运行此命令将所有流量路由到各个微服务的 `v1` 版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-v1.yaml
|
||||
```
|
||||
|
||||
3. 在浏览器中打开 Bookinfo 站点。网址为 `http://$GATEWAY_URL/productpage`, 其中 `$GATEWAY_URL` 是 Ingress 的外部 IP 地址,其描述参见 [Bookinfo](https://istio.io/latest/zh/docs/examples/bookinfo/#determine-the-ingress-IP-and-port) 文档。
|
||||
|
||||
请注意,不管刷新多少次,页面的评论部分都不会显示评价星级的内容。 这是因为 Istio 被配置为将星级评价的服务的所有流量都路由到了 `reviews:v1` 版本,而该版本的服务不访问带评价星级的服务。
|
||||
|
||||
4. 使用下面的命令把 50% 的流量从 `reviews:v1` 转移到 `reviews:v3`
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-50-v3.yaml
|
||||
```
|
||||
|
||||
5. 等待几秒钟,等待新的规则传播到代理中生效,确认规则已被替换。刷新浏览器中的 `/productpage` 页面,大约有 50% 的几率会看到页面中带**红色**星级的评价内容。 这是因为 `reviews` 的 `v3` 版本可以访问带星级评价,但 `v1` 版本不能
|
||||
|
||||
6. 如果您认为 `reviews:v3` 微服务已经稳定,您可以通过应用 Virtual Service 规则将 100% 的流量路由 `reviews:v3`
|
||||
|
||||
```bash
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-v3.yaml
|
||||
```
|
||||
|
||||
7. 现在,当您刷新 `/productpage` 时,您将始终看到带有**红色**星级评分的书评
|
||||
|
||||
8. 清理路由规则
|
||||
|
||||
```bash
|
||||
kubectl delete httproute reviews
|
||||
```
|
||||
|
||||
## 清理示例环境
|
||||
|
||||
```bash
|
||||
samples/bookinfo/platform/kube/cleanup.sh
|
||||
```
|
||||
|
||||
176
网关/Istio/通过Istio实现灰度发布.md
Normal file
176
网关/Istio/通过Istio实现灰度发布.md
Normal file
@@ -0,0 +1,176 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 通过Istio实现灰度发布
|
||||
|
||||
部署测试示例 Nginx Deployment v1和v2
|
||||
|
||||
1. 部署 v1 版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-v1.yaml
|
||||
```
|
||||
|
||||
2. 部署 v2 版本
|
||||
|
||||
```bash
|
||||
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-v2.yaml
|
||||
```
|
||||
|
||||
## 配合 Istio APIs 实现灰度发布
|
||||
|
||||
1. 创建 Nginx Service
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-deployment-service
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
2. 创建 Nginx Gateway 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: nginx-gateway
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
istio: ingressgateway
|
||||
servers:
|
||||
- port:
|
||||
number: 443
|
||||
name: https
|
||||
protocol: HTTPS
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
tls:
|
||||
mode: SIMPLE
|
||||
credentialName: example-tls # 替换为你的证书,这个 secret 必须在 istio-system 命名空间
|
||||
EOF
|
||||
```
|
||||
|
||||
3. 创建 DestinationRule 资源
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: DestinationRule
|
||||
metadata:
|
||||
name: nginx-destination
|
||||
spec:
|
||||
host: nginx-deployment-service #对应 service 名称
|
||||
subsets:
|
||||
- name: v1
|
||||
labels:
|
||||
version: v1 # Pod标签
|
||||
- name: v2
|
||||
labels:
|
||||
version: v2 # Pod标签
|
||||
EOF
|
||||
```
|
||||
|
||||
4. 创建 VirtualService 资源(限制流量全部开放给 v1)
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- route:
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v1 # 对应 DestinationRule 中的 v1
|
||||
weight: 100 # 100%流量分发到 v1
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v2 # 对应 DestinationRule 中的 v2
|
||||
EOF
|
||||
```
|
||||
|
||||
5. 更新 VirtualService 资源(将 20% 流量分给 v2)
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- route:
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v1 # 对应 DestinationRule 中的 v1
|
||||
weight: 80 # 80%流量分发到 v1
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v2 # 对应 DestinationRule 中的 v2
|
||||
weight: 20 # 20%流量分发到 v2
|
||||
EOF
|
||||
```
|
||||
|
||||
6. 最后将全部流量开放给 v2
|
||||
|
||||
```yaml
|
||||
cat <<EOF | kubectl apply -f -
|
||||
apiVersion: networking.istio.io/v1
|
||||
kind: VirtualService
|
||||
metadata:
|
||||
name: nginx-virtualservice
|
||||
namespace: default
|
||||
spec:
|
||||
hosts:
|
||||
- example.com # 替换为你的域名
|
||||
gateways:
|
||||
- nginx-gateway
|
||||
http:
|
||||
- route:
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v1 # 对应 DestinationRule 中的 v1
|
||||
- destination:
|
||||
host: nginx-deployment-service.default.svc.cluster.local # 指对应的 service 名称
|
||||
port:
|
||||
number: 80
|
||||
subset: v2 # 对应 DestinationRule 中的 v2
|
||||
weight: 100 # 100%流量分发到 v2
|
||||
EOF
|
||||
```
|
||||
|
||||
7. 完成灰度发布(HTTPS同理)。
|
||||
@@ -69,7 +69,7 @@
|
||||
1. 下载 ezdown
|
||||
|
||||
```bash
|
||||
wget https://github.com/easzlab/kubeasz/releases/download/3.6.2/ezdown && chmod 777 ezdown
|
||||
wget https://github.com/easzlab/kubeasz/releases/download/3.6.8/ezdown && chmod 777 ezdown
|
||||
```
|
||||
|
||||
> 下载支持 Docker 的版本
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
ntpdate -u ntp.aliyun.com && date
|
||||
```
|
||||
|
||||
3. 配置定时任务
|
||||
|
||||
```bash
|
||||
0 2 * * * /usr/bin/ntpdate -u ntp.aliyun.com && /bin/date
|
||||
```
|
||||
|
||||
> 离线环境使用此篇文档同步
|
||||
>
|
||||
> [NTP时间同步](https://gitee.com/offends/Linux/blob/main/Docs/NTP%E6%97%B6%E9%97%B4%E5%90%8C%E6%AD%A5.md)
|
||||
@@ -120,13 +126,15 @@
|
||||
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
|
||||
net.bridge.bridge-nf-call-ip6tables = 1
|
||||
net.bridge.bridge-nf-call-iptables = 1
|
||||
net.ipv6.conf.all.disable_ipv6 = 1
|
||||
net.ipv6.conf.default.disable_ipv6 = 1
|
||||
net.ipv4.ip_forward = 1
|
||||
vm.swappiness = 0
|
||||
EOF
|
||||
```
|
||||
|
||||
加载
|
||||
|
||||
|
||||
```bash
|
||||
sysctl --system
|
||||
```
|
||||
|
||||
@@ -116,20 +116,20 @@
|
||||
|
||||
## 安装并初始化Rke
|
||||
|
||||
[RKE二进制文件](https://github.com/rancher/rke/releases/)
|
||||
[RKE二进制文件](https://github.com/rancher/rke/releases/) [官方中国国内二进制文件](https://mirror.rancher.cn/#rke/)
|
||||
|
||||
1. 下载 RKE 二进制文件,并添加到可执行路径下
|
||||
|
||||
> 1.8 版本是 RKE 1.x 系列的最终版本
|
||||
|
||||
```bash
|
||||
wget https://github.com/rancher/rke/releases/download/v1.8.6/rke_linux-amd64
|
||||
wget https://github.com/rancher/rke/releases/download/v1.8.9/rke_linux-amd64
|
||||
```
|
||||
|
||||
2. 授权
|
||||
|
||||
```bash
|
||||
chmod 777 rke_linux-amd64 && mv rke_linux-amd64 /usr/local/bin/rke
|
||||
install -o root -g root -m 0755 rke_linux-amd64 /usr/local/bin/rke
|
||||
```
|
||||
|
||||
### 方法一 (不推荐怪麻烦的请看"方法二")
|
||||
@@ -209,6 +209,16 @@ sed -i '/^ingress:$/,/^ provider:/ s/provider: ""/provider: "none"/' cluster.ym
|
||||
...
|
||||
```
|
||||
|
||||
**更换镜像仓库**(适用于离线环境)
|
||||
|
||||
```yaml
|
||||
private_registries:
|
||||
- url: registry.cn-hangzhou.aliyuncs.com # 仅为示例
|
||||
is_default: true # 所有的系统镜像都将使用该镜像仓库进行拉取
|
||||
user: $user
|
||||
password: $password
|
||||
```
|
||||
|
||||
3. 基础参数修改
|
||||
|
||||
```bash
|
||||
@@ -390,7 +400,14 @@ rke etcd snapshot-restore --config cluster.yml --name <快照名称>
|
||||
curl -sfL https://gitee.com/offends/Kubernetes/raw/main/File/Shell/restore-rkestate-config.sh | bash -s
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 基础命令
|
||||
|
||||
- 查看集群所需镜像
|
||||
|
||||
```bash
|
||||
rke config --system-images
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
7
部署文档/Rancher/如何在国内使用Rancher.md
Normal file
7
部署文档/Rancher/如何在国内使用Rancher.md
Normal file
@@ -0,0 +1,7 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 如何在国内使用Rancher
|
||||
|
||||
> 网页地址记录
|
||||
|
||||
[官方文档](https://docs.rancher.cn/docs/rancher2/best-practices/use-in-china/)
|
||||
Reference in New Issue
Block a user