前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Service Mesh - Istio安装与部署

Service Mesh - Istio安装与部署

作者头像
端碗吹水
发布2020-12-23 11:48:12
1.3K0
发布2020-12-23 11:48:12
举报
文章被收录于专栏:程序猿的大杂烩

安装与部署:如何安装Istio?它都支持哪些环境和部署方式?

首先,我们需要准备一个Kubernetes环境:

下载Istio

在当前版本Istio的安装与部署已经变得非常简单了,只需要几个简单的步骤就能将Istio环境搭建起来。首先要做的是下载Istio(在文档中核对Istio支持的k8s版本):

获取下载脚本并执行:

代码语言:javascript
复制
[root@m1 ~]# curl -L https://istio.io/downloadIstio | sh -

将下载好的istio目录移动到合适的位置下:

代码语言:javascript
复制
[root@m1 ~]# mv istio-1.8.1/ /usr/local

配置环境变量:

代码语言:javascript
复制
[root@m1 ~]# vim /etc/profile
export ISTIO_HOME=/usr/local/istio-1.8.1
export PATH=$PATH:$ISTIO_HOME/bin
[root@m1 ~]# source /etc/profile

验证 istioctl 命令是否可正常工作:

代码语言:javascript
复制
[root@m1 ~]# istioctl version
no running Istio pods in "istio-system"
1.8.1
[root@m1 ~]# 

安装Istio

配置档案(configuration profile):

  • 安装时选择不同的 profile 会安装不同的组件,官方文档

使用 istioctl 的安装方式:

安装方式

示例

默认安装

istioctl manifest apply

选择profile

istioctl manifest apply --set profile=demo

自定义安装选项

istioctl manifest apply --set addonComponents.grafana.enabled=true

自定义安装清单

istioctl manifest apply --set installPackagePath=<发布路径>/install/kubernetes/operator/charts

在学习、实验环境我们可以选择 demo 这个 profile 进行安装,如下示例:

代码语言:javascript
复制
[root@m1 ~]# istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete
[root@m1 ~]# 

查看istio相应的 namespace 和 pod 是否已经正常创建:

代码语言:javascript
复制
[root@m1 ~]# kubectl get ns |grep istio
istio-system           Active   7m10s
[root@m1 ~]# kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-egressgateway-d84f95b69-dmpzf     1/1     Running   0          6m28s
istio-ingressgateway-75f6d79f48-5lr5b   1/1     Running   0          6m28s
istiod-c9f6864c4-5kjz7                  1/1     Running   0          7m50s
[root@m1 ~]# 

检查 istio 的 CRD 和 API 资源:

代码语言:javascript
复制
[root@m1 ~]# kubectl get crd |grep istio
authorizationpolicies.security.istio.io               2020-12-21T02:53:41Z
destinationrules.networking.istio.io                  2020-12-21T02:53:41Z
envoyfilters.networking.istio.io                      2020-12-21T02:53:41Z
gateways.networking.istio.io                          2020-12-21T02:53:41Z
istiooperators.install.istio.io                       2020-12-21T02:53:41Z
peerauthentications.security.istio.io                 2020-12-21T02:53:41Z
requestauthentications.security.istio.io              2020-12-21T02:53:41Z
serviceentries.networking.istio.io                    2020-12-21T02:53:41Z
sidecars.networking.istio.io                          2020-12-21T02:53:41Z
virtualservices.networking.istio.io                   2020-12-21T02:53:41Z
workloadentries.networking.istio.io                   2020-12-21T02:53:41Z
workloadgroups.networking.istio.io                    2020-12-21T02:53:41Z
[root@m1 ~]# kubectl api-resources |grep istio
istiooperators                 iop,io       install.istio.io               true         IstioOperator
destinationrules               dr           networking.istio.io            true         DestinationRule
envoyfilters                                networking.istio.io            true         EnvoyFilter
gateways                       gw           networking.istio.io            true         Gateway
serviceentries                 se           networking.istio.io            true         ServiceEntry
sidecars                                    networking.istio.io            true         Sidecar
virtualservices                vs           networking.istio.io            true         VirtualService
workloadentries                we           networking.istio.io            true         WorkloadEntry
workloadgroups                 wg           networking.istio.io            true         WorkloadGroup
authorizationpolicies                       security.istio.io              true         AuthorizationPolicy
peerauthentications            pa           security.istio.io              true         PeerAuthentication
requestauthentications         ra           security.istio.io              true         RequestAuthentication
[root@m1 ~]# 

添加一个命名空间标签,让Istio在之后部署应用程序时自动注入 Envoy 的 SideCar 代理:

代码语言:javascript
复制
[root@m1 ~]# kubectl label namespace default istio-injection=enabled
namespace/default labeled
[root@m1 ~]# 

安装 dashboard 组件。命令如下:

代码语言:javascript
复制
[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/addons -n istio-system

启用 kiali 作为 istio 的 dashboard:

代码语言:javascript
复制
[root@m1 ~]# istioctl dashboard kiali --address 192.168.243.138 -p 20001
http://localhost:20001/kiali

使用浏览器访问:

在 “Application” 页面可以查看 istio 组件信息:

部署 Bookinfo 应用

接下来我们部署官方提供的 demo应用 来验证 istio 的功能:

部署命令如下:

代码语言:javascript
复制
[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/bookinfo/platform/kube/bookinfo.yaml
service/details created
serviceaccount/bookinfo-details created
deployment.apps/details-v1 created
service/ratings created
serviceaccount/bookinfo-ratings created
deployment.apps/ratings-v1 created
service/reviews created
serviceaccount/bookinfo-reviews created
deployment.apps/reviews-v1 created
deployment.apps/reviews-v2 created
deployment.apps/reviews-v3 created
service/productpage created
serviceaccount/bookinfo-productpage created
deployment.apps/productpage-v1 created
[root@m1 ~]# 

确认服务、Pod 已启动:

代码语言:javascript
复制
[root@m1 ~]# kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
details-v1-79c697d759-qmtpn       2/2     Running   0          19m
productpage-v1-65576bb7bf-wqt7v   2/2     Running   0          19m
ratings-v1-7d99676f7f-jhcv6       2/2     Running   0          19m
reviews-v1-987d495c-4jlcv         2/2     Running   0          19m
reviews-v2-6c5bf657cf-n7hmw       2/2     Running   0          19m
reviews-v3-5f7b9f4f77-fpcvc       2/2     Running   0          19m
[root@m1 ~]# kubectl get svc
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
details       ClusterIP   10.102.20.100    <none>        9080/TCP   20m
kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP    112d
productpage   ClusterIP   10.97.68.248     <none>        9080/TCP   20m
ratings       ClusterIP   10.109.205.171   <none>        9080/TCP   20m
reviews       ClusterIP   10.108.11.178    <none>        9080/TCP   20m
[root@m1 ~]# 

创建 Ingress 网关,否则外部无法访问该服务:

代码语言:javascript
复制
[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
[root@m1 ~]#

确认网关和访问地址:

代码语言:javascript
复制
[root@m1 ~]# kubectl get gateways.networking.istio.io 
NAME               AGE
bookinfo-gateway   1m
[root@m1 ~]# kubectl get virtualservices.networking.istio.io 
NAME       GATEWAYS               HOSTS   AGE
bookinfo   ["bookinfo-gateway"]   ["*"]   1m
[root@m1 ~]# kubectl get svc -n istio-system 
NAME                   TYPE            CLUSTER-IP      EXTERNAL-IP                         AGE
istio-ingressgateway   LoadBalancer   10.111.237.225   <pending>     15021:32730/TCP,80:30383/TCP,443:30555/TCP,31400:30963/TCP,15443:32634/TCP   4h5m
[root@m1 ~]# 

根据官方文档的描述,当 istio-ingressgateway 服务的 EXTERNAL-IPpending 时,需要通过如下方式获取访问地址和端口号:

代码语言:javascript
复制
[root@m1 ~]# kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}'
192.168.243.140
[root@m1 ~]# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
30383

然后就可以使用浏览器访问应用页面了:

此时尝试多刷新几次页面,可以发现请求会被轮询到不同版本的 reviews 服务上:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/12/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装与部署:如何安装Istio?它都支持哪些环境和部署方式?
    • 下载Istio
      • 安装Istio
        • 部署 Bookinfo 应用
        相关产品与服务
        容器服务
        腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档