Envoy安全示例與Istio部署

一簿训、Envoy安全示例

  • https-https-proxy
cd servicemesh_in_practise/Envoy-Mesh/https-https-proxy
# 啟動(dòng)
docker-compose up

# 驗(yàn)證
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
# 啟動(dòng)
docker-compose up

# 驗(yàn)證
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
# 啟動(dòng)
docker-compose up

# 驗(yàn)證
curl 172.31.90.10:9901/listeners
listener_http::0.0.0.0:80
listener_https::0.0.0.0:443
# 查看服務(wù)跳轉(zhuǎn)
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服務(wù)
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
# 驗(yàn)證服務(wù)
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
# 啟動(dòng)
bash build.sh
docker-compose up
bash 1-start-services.sh
bash 2-start-spire-agents.sh
bash 3-create-registration-entries.sh

驗(yàn)證


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
# 驗(yàn)證
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命名空間打標(biāo)簽谆沃,在這個(gè)命名空間啟動(dòng)的容器快骗,都會(huì)自動(dòng)注入sidecar的容器
kubectl label namespace default istio-injection=enabled
namespace/default labeled
# 驗(yàn)證
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官網(wǎng):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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末锉矢,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子齿尽,更是在濱河造成了極大的恐慌沽损,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,080評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件循头,死亡現(xiàn)場(chǎng)離奇詭異绵估,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)贷岸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,422評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門壹士,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人偿警,你說我怎么就攤上這事躏救。” “怎么了?”我有些...
    開封第一講書人閱讀 157,630評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵盒使,是天一觀的道長(zhǎng)崩掘。 經(jīng)常有香客問我,道長(zhǎng)少办,這世上最難降的妖魔是什么苞慢? 我笑而不...
    開封第一講書人閱讀 56,554評(píng)論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮英妓,結(jié)果婚禮上挽放,老公的妹妹穿的比我還像新娘。我一直安慰自己蔓纠,他們只是感情好辑畦,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,662評(píng)論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著腿倚,像睡著了一般纯出。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上敷燎,一...
    開封第一講書人閱讀 49,856評(píng)論 1 290
  • 那天暂筝,我揣著相機(jī)與錄音,去河邊找鬼硬贯。 笑死焕襟,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的澄成。 我是一名探鬼主播胧洒,決...
    沈念sama閱讀 39,014評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼墨状!你這毒婦竟也來了卫漫?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,752評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤肾砂,失蹤者是張志新(化名)和其女友劉穎列赎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體镐确,經(jīng)...
    沈念sama閱讀 44,212評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡包吝,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,541評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了源葫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片诗越。...
    茶點(diǎn)故事閱讀 38,687評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖息堂,靈堂內(nèi)的尸體忽然破棺而出嚷狞,到底是詐尸還是另有隱情块促,我是刑警寧澤,帶...
    沈念sama閱讀 34,347評(píng)論 4 331
  • 正文 年R本政府宣布床未,位于F島的核電站竭翠,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏薇搁。R本人自食惡果不足惜斋扰,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,973評(píng)論 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望啃洋。 院中可真熱鬧传货,春花似錦、人聲如沸宏娄。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,777評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽绝编。三九已至,卻和暖如春貌踏,著一層夾襖步出監(jiān)牢的瞬間十饥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,006評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工祖乳, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留逗堵,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,406評(píng)論 2 360
  • 正文 我出身青樓眷昆,卻偏偏與公主長(zhǎng)得像蜒秤,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子亚斋,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,576評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容