Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update sidecar.MD #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
62 changes: 62 additions & 0 deletions module12/istio/1.http-gw/httpserver.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@


### 描述

> 本模块的实例是将服务暴露到ingess-gateway 网关服务,对外提供服务

### **核心对象:Gateway**

> 类型是Gateway (作用对象是:istio-ingressgateway,本质还是envoy)
> 作用的对象的标签是 selector: istio: ingressgateway ;
> 监听80端口(svc port) ,协议是http/tcp ,匹配的域名是simple.cncamp.io (访问时需要加头信息: -H"Host: simple.cncamp.io")

```yaml
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: simple
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- simple.cncamp.io
port:
name: http-simple
number: 80
protocol: HTTP
```

> gateway 与svc 关联
> svc 定义gateway 相关信息: gateways: - simple
```yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: simple
spec:
gateways:
- simple
hosts:
- simple.cncamp.io
http:
- match:
- port: 80
route:
- destination:
host: simple.simple.svc.cluster.local
port:
number: 80
```





### **核心对象:VirtualService**

> 高级的svc ,再svc 至上定义各种规则和策略
>
> 是istio 各种功能实现的最核心的对象


### Deploy simple

```sh
Expand Down
2 changes: 1 addition & 1 deletion module12/istio/2.l7/readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kubectl apply -f nginx.yaml -n simple
kubectl apply -f istio-specs.yaml -n simple
curl -H "Host: simple.cncamp.io" $INGRESS_IP/simple/hello
curl -H "Host: simple.cncamp.io" $INGRESS_IP/nginx
```
```
91 changes: 91 additions & 0 deletions module12/istio/4.sidecar/sidecar.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,97 @@ kubectl apply -f nginx.yaml -n sidecar
kubectl apply -f toolbox.yaml -n sidecar
```


### 排查命令
```sh
istioctl pc listener -n sidecar toolbox-666487ff7f-qc2gb --port 15006
istioctl pc route -n sidecar toolbox-666487ff7f-qc2gb --name="inbound|80||" -ojson
istioctl pc cluster -n sidecar toolbox-666487ff7f-qc2gb
istioctl pc endpoint -n sidecar toolbox-666487ff7f-qc2gb
```
#### 验证
```sh
# 查看webhook
[root@master1 sidecar]# k get mutatingwebhookconfigurations
NAME WEBHOOKS AGE
istio-revision-tag-default 4 90m
istio-sidecar-injector 4 92m
[root@master1 sidecar]#
[root@master1 sidecar]# k get mutatingwebhookconfigurations istio-sidecar-injector -oyaml


# 检查服务访问是否正常:从toolbox 访问nginx
kubectl exec -ti -n sidecar toolbox-666487ff7f-qc2gb bash
[root@toolbox-666487ff7f-qc2gb /]# curl nginx


# 从客户端toolbox梳理流量出去到nginx
[root@master1 sidecar]# docker ps |grep tool
cc659edfb835 5bd54fe7908d "/usr/local/bin/pilo…" 6 minutes ago Up 6 minutes k8s_istio-proxy_toolbox-666487ff7f-qc2gb_sidecar_260c9f68-2971-4cb1-b2ab-18ae373bf9a0_0
8e7b639357c5 centos "tail -f /dev/null" 6 minutes ago Up 6 minutes k8s_toolbox_toolbox-666487ff7f-qc2gb_sidecar_260c9f68-2971-4cb1-b2ab-18ae373bf9a0_0
4b624eeaa894 k8s.gcr.io/pause:3.2 "/pause" 7 minutes ago Up 7 minutes k8s_POD_toolbox-666487ff7f-qc2gb_sidecar_260c9f68-2971-4cb1-b2ab-18ae373bf9a0_0

[root@master1 sidecar]# docker inspect 8e7b639357c5 |grep -i pid
"Pid": 15697,
"PidMode": "",
"PidsLimit": null,
[root@master1 sidecar]# nsenter -t 15697 -n iptables-save
# Generated by iptables-save v1.4.21 on Tue Feb 15 17:32:16 2022
*raw
:PREROUTING ACCEPT [2199:411868]
:OUTPUT ACCEPT [1771:218842]
COMMIT
# Completed on Tue Feb 15 17:32:16 2022
# Generated by iptables-save v1.4.21 on Tue Feb 15 17:32:16 2022
*mangle
:PREROUTING ACCEPT [2199:411868]
:INPUT ACCEPT [2199:411868]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1771:218842]
:POSTROUTING ACCEPT [1771:218842]
COMMIT
# Completed on Tue Feb 15 17:32:16 2022
# Generated by iptables-save v1.4.21 on Tue Feb 15 17:32:16 2022
*filter
:INPUT ACCEPT [2199:411868]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1771:218842]
COMMIT
# Completed on Tue Feb 15 17:32:16 2022
# Generated by iptables-save v1.4.21 on Tue Feb 15 17:32:16 2022
*nat
:PREROUTING ACCEPT [206:12360]
:INPUT ACCEPT [206:12360]
:OUTPUT ACCEPT [42:3545]
:POSTROUTING ACCEPT [43:3605]
:ISTIO_INBOUND - [0:0]
:ISTIO_IN_REDIRECT - [0:0]
:ISTIO_OUTPUT - [0:0]
:ISTIO_REDIRECT - [0:0]
-A PREROUTING -p tcp -j ISTIO_INBOUND
# -A OUTPUT -p tcp -j ISTIO_OUTPUT
-A ISTIO_INBOUND -p tcp -m tcp --dport 15008 -j RETURN
-A ISTIO_INBOUND -p tcp -m tcp --dport 22 -j RETURN
-A ISTIO_INBOUND -p tcp -m tcp --dport 15090 -j RETURN
-A ISTIO_INBOUND -p tcp -m tcp --dport 15021 -j RETURN
-A ISTIO_INBOUND -p tcp -m tcp --dport 15020 -j RETURN
-A ISTIO_INBOUND -p tcp -j ISTIO_IN_REDIRECT
-A ISTIO_IN_REDIRECT -p tcp -j REDIRECT --to-ports 15006
-A ISTIO_OUTPUT -s 127.0.0.6/32 -o lo -j RETURN
-A ISTIO_OUTPUT ! -d 127.0.0.1/32 -o lo -m owner --uid-owner 1337 -j ISTIO_IN_REDIRECT
-A ISTIO_OUTPUT -o lo -m owner ! --uid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -m owner --uid-owner 1337 -j RETURN
-A ISTIO_OUTPUT ! -d 127.0.0.1/32 -o lo -m owner --gid-owner 1337 -j ISTIO_IN_REDIRECT
-A ISTIO_OUTPUT -o lo -m owner ! --gid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -m owner --gid-owner 1337 -j RETURN
-A ISTIO_OUTPUT -d 127.0.0.1/32 -j RETURN
-A ISTIO_OUTPUT -j ISTIO_REDIRECT
# -A ISTIO_REDIRECT -p tcp -j REDIRECT --to-ports 15001
COMMIT
# Completed on Tue Feb 15 17:32:16 2022

```

### Check clusters

```sh
Expand Down
2 changes: 1 addition & 1 deletion module12/istio/4.sidecar/toolbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ spec:
command:
- tail
- -f
- /dev/null
- /dev/null
12 changes: 12 additions & 0 deletions module12/istio/5.canary/canary-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: canary
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: canary
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,3 @@ spec:
image: cncamp/httpserver:v1.0-metrics
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: canary
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: canary
2 changes: 1 addition & 1 deletion module12/istio/5.canary/canary-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ spec:
imagePullPolicy: Always
image: cncamp/httpserver:v2.0-metrics
ports:
- containerPort: 80
- containerPort: 80
19 changes: 19 additions & 0 deletions module12/istio/5.canary/destination.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: canary
spec:
host: canary
trafficPolicy:
loadBalancer:
simple: RANDOM
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
27 changes: 27 additions & 0 deletions module12/istio/5.canary/istio-specs-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: canary
spec:
hosts:
- canary
http:
- match:
- uri:
exact: "/etc"
rewrite:
uri: "/"
route:
- destination:
host: canary
subset: v2

- match:
- uri:
exact: "*"
rewrite:
uri: "/"
route:
- destination:
host: canary
subset: v1
26 changes: 3 additions & 23 deletions module12/istio/5.canary/istio-specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,6 @@ spec:
host: canary
subset: v2
- route:
- destination:
host: canary
subset: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: canary
spec:
host: canary
trafficPolicy:
loadBalancer:
simple: RANDOM
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
- destination:
host: canary
subset: v1
5 changes: 4 additions & 1 deletion module12/istio/5.canary/readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
```sh
kubectl create ns canary
kubectl label ns canary istio-injection=enabled
kubectl apply -f canary.yaml -n canary
kubectl apply -f canary-v1.yaml -n canary
kubectl apply -f toolbox.yaml -n canary
kubectl apply -f canary-svc.yaml
```

### Access canary in toolbox
Expand All @@ -22,6 +23,7 @@ kubectl apply -f canary-v2.yaml -n canary
### Update istio specs

```sh
kubectl apply -f destination.yaml
k apply -f istio-specs.yaml -n canary
```

Expand All @@ -31,4 +33,5 @@ k apply -f istio-specs.yaml -n canary

```sh
curl canary/hello -H "user: jesse"
curl canary/hello -H "user: jesse1"
```
2 changes: 1 addition & 1 deletion module12/istio/5.canary/toolbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ spec:
command:
- tail
- -f
- /dev/null
- /dev/null
34 changes: 34 additions & 0 deletions module12/istio/installation/istio-install.MD
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
### Install istio


## istio 安装

### Istio 主要提供了以下三种安装方式,用户可以根据自己的实际需要进行选择。

- 1.使用 Istioctl 安装:istioctl 是支持多种自定义选项的的命令行工具,用户可以灵活配置,实现 Istio 组件的定制化安装。Istio 官方推荐使用该方式进行安装部署,可用于生产环境。
- 2.使用 Helm 自定义安装:这种安装方式使用 Helm charts 定义 Istio 的安装选项,目前该安装方式已被弃用。
- 3.安装独立的 Operator:该方式使用独立的 Istio operator 来安装 istio,以声明式的方式管理安装配置,目前仍处于实验阶段,不推荐在生产环境使用



#### stioctl 安装

1、使用 demo 配置文件进行安装
Istio 官方提供了针对不同场景的配置文件,这些内置的配置文件提供了对 Istio 控制平面和数据平面的定制内容。 用户可以根据实际场景选择特定的配置文件,然后结合自定义选项完成定制化安装。当前提供以下几种内置配置文件包括:

- default: 根据默认的安装选项启用组件,建议用于生产环境的部署。
- demo: 用于展示 Istio 的基本功能,支持运行 Bookinfo 应用程序和相关任务。
- minimal:使用 Istio 的流量管理功能所需的最少组件。
- remote:用于配置多集群服务网格场景下的远程集群。
- empty:不部署任何组件,可用于自定义配置的基础文件。
- preview:包含实验性功能,用于探索 Istio 新功能,但无法保证稳定性。

在选定上述配置文件之后,可以在安装 Istio 时在命令行添加一个或多个 --set <key>=<value> 选项,完成 Istio 安装插件的其他选项配置。


```sh
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.12.0
cp bin/istioctl /usr/local/bin
istioctl install --set profile=demo -y
```



### 查看自动创建sidecar 的webhook 以及启用ns 的自动注入功能
```
k get mutatingwebhookconfigurations istio-sidecar-injector -oyaml

kubectl label ns securesvc istio-injection=enabled
```
### Istio monitoring

- Grafana dashboard `7639`