Envoy安全示例与Istio部署

一、Envoy安全示例

  • https-https-proxy
cd servicemesh_in_practise/Envoy-Mesh/https-https-proxy
# 启动
docker-compose up

# 验证
curl -k https://172.31.8.2:8443
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.1, ServerName: webserver02, ServerIP: 172.31.8.12!
# 查看证书
curl http://172.31.8.12:9901/certs
{
 "certificates": [
  {
   "ca_cert": [],
   "cert_chain": [
    {
     "path": "/etc/envoy/certs/webserver.crt",
     "serial_number": "494ead58e545b429fa3fbebd5fe053797543dd1f",
     "subject_alt_names": [],
     "days_until_expiration": "3298",
     "valid_from": "2021-05-19T04:25:28Z",
     "expiration_time": "2031-05-17T04:25:28Z"
    }
   ]
  }
 ]
}
  • https-passthrough
cd servicemesh_in_practise/Envoy-Mesh/https-passthrough
# 启动
docker-compose up

# 验证
curl -k https://172.31.9.2:8443
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.1, ServerName: webserver01, ServerIP: 172.31.9.11!
  • tls-static
cd servicemesh_in_practise/Security/tls-static
# 启动
docker-compose up

# 验证
curl 172.31.90.10:9901/listeners
listener_http::0.0.0.0:80
listener_https::0.0.0.0:443
# 查看服务跳转
curl -I 172.31.90.10
HTTP/1.1 301 Moved Permanently
location: https://172.31.90.10:443/
date: Fri, 06 May 20xx xx:39:45 GMT
server: envoy
transfer-encoding: chunked
# 查看https服务
curl -k -I https://172.31.90.10:443
HTTP/1.1 200 OK
content-type: text/html; charset=utf-8
content-length: 75
server: envoy
date: Fri, 06 May 20xx xx:41:17 GMT
x-envoy-upstream-service-time: 1013
# 验证服务
curl -k https://172.31.90.10/service/gray
Hello from App behind Envoy (service gray)! hostname: e6c9e46ddb6a resolved hostname: 172.31.90.15
curl -k https://172.31.90.10/service/purple
Hello from App behind Envoy (service purple)! hostname: f9fd24599831 resolved hostname: 172.31.90.16
  • spire-example
cd servicemesh_in_practise/Security/spire-example
# 启动
bash build.sh
docker-compose up
bash 1-start-services.sh
bash 2-start-spire-agents.sh
bash 3-create-registration-entries.sh

验证


image.png
image.png

二、部署Istio

wget https://github.com/istio/istio/releases/download/1.13.3/istio-1.13.3-linux-amd64.tar.gz
tar xf istio-1.13.3-linux-amd64.tar.gz
ln -sf istio-1.13.3/bin/istioctl /usr/local/bin/
# 安装
istioctl install -y --set profile=demo
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Egress gateways installed
✔ Installation complete                                                                                                                                            Making this installation the default for injection and validation.

Thank you for installing Istio 1.13.  Please take a few minutes to tell us about your install/upgrade experience!  https://forms.gle/pzWZpAvMVBecaQ9h9
# 部署配件
kubectl apply -f samples/addons/
serviceaccount/grafana created
configmap/grafana created
service/grafana created
deployment.apps/grafana created
configmap/istio-grafana-dashboards created
configmap/istio-services-grafana-dashboards created
deployment.apps/jaeger created
service/tracing created
service/zipkin created
service/jaeger-collector created
serviceaccount/kiali created
configmap/kiali created
clusterrole.rbac.authorization.k8s.io/kiali-viewer created
clusterrole.rbac.authorization.k8s.io/kiali created
clusterrolebinding.rbac.authorization.k8s.io/kiali created
role.rbac.authorization.k8s.io/kiali-controlplane created
rolebinding.rbac.authorization.k8s.io/kiali-controlplane created
service/kiali created
deployment.apps/kiali created
serviceaccount/prometheus created
configmap/prometheus created
clusterrole.rbac.authorization.k8s.io/prometheus created
clusterrolebinding.rbac.authorization.k8s.io/prometheus created
service/prometheus created
deployment.apps/prometheus created
# 验证
kubectl -n istio-system get po
NAME                                    READY   STATUS    RESTARTS   AGE
grafana-67f5ccd9d7-lzrwm                1/1     Running   0          6m44s
istio-egressgateway-7569bf4864-q5txl    1/1     Running   0          7m57s
istio-ingressgateway-5d6f5f9d78-fmfdp   1/1     Running   0          7m57s
istiod-d56576b74-4nr7g                  1/1     Running   0          9m14s
jaeger-78cb4f7d4b-wr8gt                 1/1     Running   0          6m44s
kiali-c946fb5bc-m8dfh                   1/1     Running   0          6m43s
prometheus-7cc96d969f-5qx24             2/2     Running   0          6m42s
# 给default命名空间打标签,在这个命名空间启动的容器,都会自动注入sidecar的容器
kubectl label namespace default istio-injection=enabled
namespace/default labeled
# 验证
kubectl apply -f samples/sleep/sleep.yaml
serviceaccount/sleep created
service/sleep created
deployment.apps/sleep created
kubectl get po
NAME                     READY   STATUS    RESTARTS   AGE
sleep-698cfc4445-ldm4l   2/2     Running   0          90s
# 查看pod同步到istio信息
istioctl ps
NAME                                                   CLUSTER        CDS        LDS        EDS        RDS          ISTIOD                     VERSION
istio-egressgateway-7569bf4864-q5txl.istio-system      Kubernetes     SYNCED     SYNCED     SYNCED     NOT SENT     istiod-d56576b74-4nr7g     1.13.3
istio-ingressgateway-5d6f5f9d78-fmfdp.istio-system     Kubernetes     SYNCED     SYNCED     SYNCED     NOT SENT     istiod-d56576b74-4nr7g     1.13.3
sleep-698cfc4445-ldm4l.default                         Kubernetes     SYNCED     SYNCED     SYNCED     SYNCED       istiod-d56576b74-4nr7g     1.13.3
# 查看listener信息
istioctl pc listener sleep-698cfc4445-ldm4l
ADDRESS        PORT  MATCH                                                                                         DESTINATION
10.96.0.10     53    ALL                                                                                           Cluster: outbound|53||kube-dns.kube-system.svc.cluster.local
0.0.0.0        80    Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 80
0.0.0.0        80    ALL                                                                                           PassthroughCluster
10.100.213.173 443   ALL                                                                                           Cluster: outbound|443||istio-ingressgateway.istio-system.svc.cluster.local
10.106.15.6    443   ALL                                                                                           Cluster: outbound|443||istiod.istio-system.svc.cluster.local
10.108.102.187 443   ALL                                                                                           Cluster: outbound|443||istio-egressgateway.istio-system.svc.cluster.local
10.96.0.1      443   ALL                                                                                           Cluster: outbound|443||kubernetes.default.svc.cluster.local
10.100.69.105  3000  Trans: raw_buffer; App: http/1.1,h2c                                                          Route: grafana.istio-system.svc.cluster.local:3000
10.100.69.105  3000  ALL                                                                                           Cluster: outbound|3000||grafana.istio-system.svc.cluster.local
0.0.0.0        9090  Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 9090
0.0.0.0        9090  ALL                                                                                           PassthroughCluster
10.96.0.10     9153  Trans: raw_buffer; App: http/1.1,h2c                                                          Route: kube-dns.kube-system.svc.cluster.local:9153
10.96.0.10     9153  ALL                                                                                           Cluster: outbound|9153||kube-dns.kube-system.svc.cluster.local
0.0.0.0        9411  Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 9411
0.0.0.0        9411  ALL                                                                                           PassthroughCluster
10.106.78.117  14250 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: jaeger-collector.istio-system.svc.cluster.local:14250
10.106.78.117  14250 ALL                                                                                           Cluster: outbound|14250||jaeger-collector.istio-system.svc.cluster.local
10.106.78.117  14268 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: jaeger-collector.istio-system.svc.cluster.local:14268
10.106.78.117  14268 ALL                                                                                           Cluster: outbound|14268||jaeger-collector.istio-system.svc.cluster.local
0.0.0.0        15001 ALL                                                                                           PassthroughCluster
0.0.0.0        15001 Addr: *:15001                                                                                 Non-HTTP/Non-TCP
0.0.0.0        15006 Addr: *:15006                                                                                 Non-HTTP/Non-TCP
0.0.0.0        15006 Trans: tls; App: istio-http/1.0,istio-http/1.1,istio-h2; Addr: 0.0.0.0/0                      InboundPassthroughClusterIpv4
0.0.0.0        15006 Trans: raw_buffer; App: http/1.1,h2c; Addr: 0.0.0.0/0                                         InboundPassthroughClusterIpv4
0.0.0.0        15006 Trans: tls; App: TCP TLS; Addr: 0.0.0.0/0                                                     InboundPassthroughClusterIpv4
0.0.0.0        15006 Trans: raw_buffer; Addr: 0.0.0.0/0                                                            InboundPassthroughClusterIpv4
0.0.0.0        15006 Trans: tls; Addr: 0.0.0.0/0                                                                   InboundPassthroughClusterIpv4
0.0.0.0        15006 Trans: tls; App: istio,istio-peer-exchange,istio-http/1.0,istio-http/1.1,istio-h2; Addr: *:80 Cluster: inbound|80||
0.0.0.0        15006 Trans: raw_buffer; Addr: *:80                                                                 Cluster: inbound|80||
0.0.0.0        15010 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 15010
0.0.0.0        15010 ALL                                                                                           PassthroughCluster
10.106.15.6    15012 ALL                                                                                           Cluster: outbound|15012||istiod.istio-system.svc.cluster.local
0.0.0.0        15014 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 15014
0.0.0.0        15014 ALL                                                                                           PassthroughCluster
0.0.0.0        15021 ALL                                                                                           Inline Route: /healthz/ready*
10.100.213.173 15021 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: istio-ingressgateway.istio-system.svc.cluster.local:15021
10.100.213.173 15021 ALL                                                                                           Cluster: outbound|15021||istio-ingressgateway.istio-system.svc.cluster.local
0.0.0.0        15090 ALL                                                                                           Inline Route: /stats/prometheus*
10.100.213.173 15443 ALL                                                                                           Cluster: outbound|15443||istio-ingressgateway.istio-system.svc.cluster.local
0.0.0.0        16685 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 16685
0.0.0.0        16685 ALL                                                                                           PassthroughCluster
0.0.0.0        20001 Trans: raw_buffer; App: http/1.1,h2c                                                          Route: 20001
0.0.0.0        20001 ALL                                                                                           PassthroughCluster
10.100.213.173 31400 ALL                                                                                           Cluster: outbound|31400||istio-ingressgateway.istio-system.svc.cluster.local
# 查看cluster
istioctl pc cluster sleep-698cfc4445-ldm4l.default
SERVICE FQDN                                            PORT      SUBSET     DIRECTION     TYPE             DESTINATION RULE
                                                        80        -          inbound       ORIGINAL_DST
BlackHoleCluster                                        -         -          -             STATIC
InboundPassthroughClusterIpv4                           -         -          -             ORIGINAL_DST
PassthroughCluster                                      -         -          -             ORIGINAL_DST
agent                                                   -         -          -             STATIC
grafana.istio-system.svc.cluster.local                  3000      -          outbound      EDS
istio-egressgateway.istio-system.svc.cluster.local      80        -          outbound      EDS
istio-egressgateway.istio-system.svc.cluster.local      443       -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     80        -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     443       -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     15021     -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     15443     -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     31400     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   443       -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15010     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15012     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15014     -          outbound      EDS
jaeger-collector.istio-system.svc.cluster.local         9411      -          outbound      EDS
jaeger-collector.istio-system.svc.cluster.local         14250     -          outbound      EDS
jaeger-collector.istio-system.svc.cluster.local         14268     -          outbound      EDS
kiali.istio-system.svc.cluster.local                    9090      -          outbound      EDS
kiali.istio-system.svc.cluster.local                    20001     -          outbound      EDS
kube-dns.kube-system.svc.cluster.local                  53        -          outbound      EDS
kube-dns.kube-system.svc.cluster.local                  9153      -          outbound      EDS
kubernetes.default.svc.cluster.local                    443       -          outbound      EDS
prometheus.istio-system.svc.cluster.local               9090      -          outbound      EDS
prometheus_stats                                        -         -          -             STATIC
sds-grpc                                                -         -          -             STATIC
sleep.default.svc.cluster.local                         80        -          outbound      EDS
tracing.istio-system.svc.cluster.local                  80        -          outbound      EDS
tracing.istio-system.svc.cluster.local                  16685     -          outbound      EDS
xds-grpc                                                -         -          -             STATIC
zipkin                                                  -         -          -             STRICT_DNS
zipkin.istio-system.svc.cluster.local                   9411      -          outbound      EDS
# 查看route信息
istioctl pc route sleep-698cfc4445-ldm4l.default
NAME                                                          DOMAINS                                               MATCH                  VIRTUAL SERVICE
                                                              *                                                     /healthz/ready*
istio-ingressgateway.istio-system.svc.cluster.local:15021     *                                                     /*
80                                                            istio-egressgateway.istio-system, 10.108.102.187      /*
80                                                            istio-ingressgateway.istio-system, 10.100.213.173     /*
80                                                            sleep, sleep.default + 1 more...                      /*
80                                                            tracing.istio-system, 10.97.164.49                    /*
InboundPassthroughClusterIpv4                                 *                                                     /*
jaeger-collector.istio-system.svc.cluster.local:14250         *                                                     /*
inbound|80||                                                  *                                                     /*
inbound|80||                                                  *                                                     /*
InboundPassthroughClusterIpv4                                 *                                                     /*
jaeger-collector.istio-system.svc.cluster.local:14268         *                                                     /*
grafana.istio-system.svc.cluster.local:3000                   *                                                     /*
kube-dns.kube-system.svc.cluster.local:9153                   *                                                     /*
9090                                                          kiali.istio-system, 10.107.148.152                    /*
9090                                                          prometheus.istio-system, 10.106.229.76                /*
9411                                                          jaeger-collector.istio-system, 10.106.78.117          /*
9411                                                          zipkin.istio-system, 10.99.122.65                     /*
15010                                                         istiod.istio-system, 10.106.15.6                      /*
15014                                                         istiod.istio-system, 10.106.15.6                      /*
16685                                                         tracing.istio-system, 10.97.164.49                    /*
20001                                                         kiali.istio-system, 10.107.148.152                    /*
                                                              *                                                     /stats/prometheus*

istio官网:https://istio.io/latest/docs/setup/getting-started/

三、页面展示

  • kiali
# 下载示例代码
git clone https://github.com/iKubernetes/istio-in-practise.git
cd istio-in-practise/Traffic-Management-Basics/kiali-80
kubectl apply -f .

添加域名解析,访问kiali


image.png
image.png
image.png
  • prometheus
cd istio-in-practise/Traffic-Management-Basics/prometheus
kubectl apply -f .

添加域名解析,访问prometheus


image.png
  • grafana
cd istio-in-practise/Traffic-Management-Basics/grafana
kubectl apply -f .

添加域名解析,访问grafana


image.png
  • jaeger
cd istio-in-practise/Traffic-Management-Basics/tracing
kubectl apply -f .

添加域名解析,访问jaeger


image.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容