欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

使用 Helm Chart 部署及卸载 istio

程序员文章站 2022-04-21 17:27:33
部署 istio 1.添加 istio 官方的 helm 仓库 2.是否添加成功 NAME CHART VERSION APP VERSION DESCRIPTION istio/istio 1.3.3 1.3.3 Helm chart for all istio components istio/ ......

部署 istio

1.添加 istio 官方的 helm 仓库

helm repo add istio   https://storage.googleapis.com/istio-release/releases/1.3.3/charts/

2.是否添加成功

helm search repo istio

name chart version app version description
istio/istio 1.3.3 1.3.3 helm chart for all istio components
istio/istio-cni 1.3.3 1.3.3 helm chart for istio-cni components
istio/istio-init 1.3.3 1.3.3 helm chart to initialize istio crds

3.创建 istio-system 命名空间

kubectl create ns istio-system

4.创建 istio 所需的 crd 文件

helm install istio-init istio/istio-init -n istio-system

5.检查 crd 文件是否创建完成,输出为23

kubectl get crds | grep 'istio.io' | wc -l

23

6.部署 istio

helm install istio istio/istio -n istio-system

name: istio
last deployed: thu oct 24 12:05:06 2019
namespace: istio-system
status: deployed
revision: 1
notes:
thank you for installing istio.

your release is named istio.

to get started running application with istio, execute the following steps:

  1. label namespace that application object will be deployed to by the following command (take default namespace as an example)

kubectl label namespace default istio-injection=enabled
​ kubectl get namespace -l istio-injection

  1. deploy your applications

$ kubectl apply -f .yaml

for more information on running istio, visit:

卸载 istio

1.卸载 istio

helm -n istio-system uninstall istio

2.删除 istio crd 文件

helm -n istio-system uninstall istio-init

kubectl delete crd `kubectl get crd | grep istio| awk '{print $1}'`

一键部署及卸载 istio 的脚本

部署脚本

#!/bin/bash

# add istio official repo
add_repo(){
  version=$1
  repo="https://storage.googleapis.com/istio-release/releases/${version}/charts/"
  helm repo add istio $repo

  status_cmd=`echo $?`
  check_repo_cmd=`helm repo list | grep $repo | wc -l`
  echo "$status_cmd"
  echo "$check_repo_cmd"
  while [[ $status_cmd != 0 && $check_repo_cmd -ge 1 ]]
  do
    sleep 5
    helm repo add istio $repo

    status_cmd=`echo $?`
    check_repo_cmd=`helm repo list | grep $repo | wc -l`
  done
}

# create istio-system namespace
create_namespace() {
  namespace=$1
  kubectl create ns ${namespace}

  status_cmd=`echo $?`
  while [[ $status_cmd != 0 ]]
  do
    sleep 5
    kubectl create ns ${namespace}
    status_cmd=`echo $?`
  done
}

# create crd need for istio
create_crd() {
  namespace=$1
  helm install istio-init istio/istio-init -n ${namespace}
  crd_count=`kubectl get crds | grep 'istio.i' | wc -l`

  while [[ ${crd_count} != 23 ]]
  do
    sleep 5
    crd_count=`kubectl get crds | grep 'istio.io' | wc -l`
  done

  echo 'istio crd create successful'
}

# deploy istio related components
deploy_istio() {
  namespace=$1
  version=$2
  helm install istio istio/istio -n ${namespace}

  check() {
     kubectl -n ${namespace}  get deploy | grep istio | awk '{print "deployment/"$1}' | while read line ;
     do
       kubectl rollout status $line -n ${namespace};
     done
  }
  check

  echo "istio is deployed successful"
}

main(){
  istio_version="1.3.3"
  istio_namespace="istio-system"
  add_repo $istio_version
  if [[ `kubectl get ns | grep $istio_namespace | wc -l ` == 0 && `kubectl get ns $istio_namespace | grep -v name | wc -l` == 0 ]] ;then
    create_namespace $istio_namespace
  fi
  create_crd $istio_namespace
  deploy_istio $istio_namespace $istio_version
}

main

卸载脚本

#!/bin/bash

helm -n istio-system uninstall istio 
helm -n istio-system uninstall istio-init
kubectl delete crd `kubectl get crd | grep istio | awk '{print $1}'` 
kubectl delete ns istio-system

注意:卸载需谨慎,删除了 istio-system 的命名空间

总结

上述步骤使用的是 istio 官方提供的默认配置,如果你想要自定配置,可以阅读 values.yaml 文件后,通过 --set 的方式修改,或者直接修改 chart。

本文由博客一文多发平台 openwrite 发布!