1. 程式人生 > >《Istio官方文件》Kubernetes-Istio網格擴充套件

《Istio官方文件》Kubernetes-Istio網格擴充套件

Istio網格擴充套件

將虛擬機器和裸機主機整合到部署在Kubernetes上的Istio網格中的說明如下。

先決條件

  • 按照安裝指南中的說明在Kubernetes上安裝Istio 。
  • 機器必須具有到網格中節點的IP連線。這通常需要一個VPC或一個VPN,以及一個提供直接(沒有NAT或防火牆拒絕)路由到節點的容器網路。機器不需要訪問由Kubernetes分配的叢集IP地址。
  • Istio控制平面服務(Pilot,Mixer,CA)和Kubernetes DNS伺服器必須可以從虛擬機器中訪問。這通常是使用。您也可以使用NodePort,在虛擬機器上執行Istio元件,或使用自定義網路配置,單獨的文件將覆蓋這些高階配置。

安裝步驟

安裝程式包括準備用於擴充套件,安裝和配置每個虛擬機器的網格。

作為發行包的一部分,以及提供了一個幫助Kubernetes安裝的示例指令碼。檢查支援的指令碼內容和環境變數(如GCP_OPTS)。

幫助配置計算機的示例指令碼可作為發行包的一部分,也可以在。您應該根據您的配置工具和DNS要求對其進行自定義。

準備Kubernetes叢集進行擴充套件

  • 為Kube DNS,Pilot,Mixer和CA設定內部負載均衡器(ILB)。這一步是特定於每個雲提供商,所以你可能需要編輯註釋。
    kubectl apply -f install/kubernetes/mesh-expansion.yaml
  • 生成Istio ‘cluster.env’配置並部署在虛擬機器中。該檔案包含要攔截的叢集IP地址範圍。
    export GCP_OPTS="--zone MY_ZONE --project MY_PROJECT"
    install/tools/setupMeshEx.sh generateClusterEnv MY_CLUSTER_NAME

生成檔案示例:

cat cluster.env

ISTIO_SERVICE_CIDR=10.63.240.0/20
  • 生成在虛擬機器中使用的DNS配置檔案。這將允許VM上的應用程式解析叢集服務名稱,這些名稱將被sidecar攔截並轉發。
    # Make sure your kubectl context is set to your cluster
    install/tools/setupMeshEx.sh generateDnsmasq

生成檔案示例:

cat kubedns
server=/svc.cluster.local/10.150.0.7
address=/istio-mixer/10.150.0.8
address=/istio-pilot/10.150.0.6
address=/istio-ca/10.150.0.9
address=/istio-mixer.istio-system/10.150.0.8
address=/istio-pilot.istio-system/10.150.0.6
address=/istio-ca.istio-system/10.150.0.9

設定機器

例如,您可以使用以下“全包”指令碼來複制和安裝設定:

# Check what the script does to see that it meets your needs.
export GCP_OPTS="--zone MY_ZONE --project MY_PROJECT"
# change to the namespace you wish to use for VMs but 'vm' is what the bookinfo guide assumes
export SERVICE_NAMESPACE=vm
install/tools/setupMeshEx.sh machineSetup VM_NAME

或者等效的手動步驟:

–手動設定步驟開始–

  • 將配置檔案和Istio Debian檔案複製到加入叢集的每臺機器上。將檔案儲存為/etc/dnsmasq.d/kubedns和/var/lib/istio/envoy/cluster.env。
  • 配置和驗證DNS設定。這可能需要安裝dnsmasq並直接或通過DHCP指令碼新增到/etc/resolv.conf中。要驗證,請檢查虛擬機器是否可以解析名稱並連線到pilot,例如:

在VM /外部主機上:

host istio-pilot.istio-system

生成訊息示例:

# Verify you get the same address as shown as "EXTERNAL-IP" in 'kubectl get svc -n istio-system istio-pilot-ilb'
istio-pilot.istio-system has address 10.150.0.6

檢查您是否可以解決叢集IP。實際地址將取決於您的部署。

host istio-pilot.istio-system.svc.cluster.local.

生成訊息示例:

istio-pilot.istio-system.svc.cluster.local has address 10.63.247.248

同樣檢查istio-ingress:

host istio-ingress.istio-system.svc.cluster.local.

生成訊息示例:

istio-ingress.istio-system.svc.cluster.local has address 10.63.243.30
  • 通過檢查虛擬機器是否可以連線到Pilot和節點來驗證連線。
    curl 'http://istio-pilot.istio-system:8080/v1/registration/istio-pilot.istio-system.svc.cluster.local|http-discovery'
    {
      "hosts": [
       {
        "ip_address": "10.60.1.4",
        "port": 8080
       }
      ]
    }
    
    # On the VM, use the address above. It will directly connect to the pod running istio-pilot.
    curl 'http://10.60.1.4:8080/v1/registration/istio-pilot.istio-system.svc.cluster.local|http-discovery'
  • 提取最初的Istio認證機密並將其複製到機器上。Istio的預設安裝包括Istio CA,即使禁用自動“mTLS”設定(它為每個服務帳戶建立機密,機密被命名為istio.<serviceaccount>),也會生成Istio機密。建議您執行此步驟,以便日後啟用mTLS,並升級到將預設啟用mTLS的未來版本。
    # ACCOUNT defaults to 'default', or SERVICE_ACCOUNT environment variable
    # NAMESPACE defaults to current namespace, or SERVICE_NAMESPACE environment variable
    # (this step is done by machineSetup)
    # On a mac either brew install base64 or set BASE64_DECODE="/usr/bin/base64 -D"
    install/tools/setupMeshEx.sh machineCerts ACCOUNT NAMESPACE

生成的檔案(key.pem,root-cert.pem,cert-chain.pem)必須被複制到每一臺機器上的/etc/certs目錄下,並通過istio代理讀取。

  • 安裝Istio Debian檔案並啟動’istio’和’istio-auth-node-agent’服務。從github發行版獲取debian軟體包或:
    # Note: This will be replaced with an 'apt-get' command once the repositories are setup.
    
    source istio.VERSION # defines version and URLs env var
    curl -L ${PILOT_DEBIAN_URL}/istio-agent.deb > ${ISTIO_STAGING}/istio-agent.deb
    curl -L ${AUTH_DEBIAN_URL}/istio-auth-node-agent.deb > ${ISTIO_STAGING}/istio-auth-node-agent.deb
    curl -L ${PROXY_DEBIAN_URL}/istio-proxy.deb > ${ISTIO_STAGING}/istio-proxy.deb
    
    dpkg -i istio-proxy-envoy.deb
    dpkg -i istio-agent.deb
    dpkg -i istio-auth-node-agent.deb
    
    systemctl start istio
    systemctl start istio-auth-node-agent

–手動設定步驟結束–

設定完成後,機器應能夠訪問在Kubernetes叢集或其他網格擴充套件機器上執行的服務。

# Assuming you install bookinfo in 'bookinfo' namespace
curl productpage.bookinfo.svc.cluster.local:9080
... html content ...

檢查程序是否正在執行:

ps aux |grep istio

root      6941  0.0  0.2  75392 16820 ?        Ssl  21:32   0:00 /usr/local/istio/bin/node_agent --logtostderr
root      6955  0.0  0.0  49344  3048 ?        Ss   21:32   0:00 su -s /bin/bash -c INSTANCE_IP=10.150.0.5 POD_NAME=demo-vm-1 POD_NAMESPACE=default exec /usr/local/bin/pilot-agent proxy > /var/log/istio/istio.log istio-proxy
istio-p+  7016  0.0  0.1 215172 12096 ?        Ssl  21:32   0:00 /usr/local/bin/pilot-agent proxy
istio-p+  7094  4.0  0.3  69540 24800 ?        Sl   21:32   0:37 /usr/local/bin/envoy -c /etc/istio/proxy/envoy-rev1.json --restart-epoch 1 --drain-time-s 2 --parent-shutdown-time-s 3 --service-cluster istio-proxy --service-node sidecar~10.150.0.5~demo-vm-1.default~default.svc.cluster.local

Istio身份驗證節點代理是健康的:

sudo systemctl status istio-auth-node-agent

● istio-auth-node-agent.service - istio-auth-node-agent: The Istio auth node agent
   Loaded: loaded (/lib/systemd/system/istio-auth-node-agent.service; disabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-10-13 21:32:29 UTC; 9s ago
     Docs: https://istio.io/
 Main PID: 6941 (node_agent)
    Tasks: 5
   Memory: 5.9M
      CPU: 92ms
   CGroup: /system.slice/istio-auth-node-agent.service
           └─6941 /usr/local/istio/bin/node_agent --logtostderr

Oct 13 21:32:29 demo-vm-1 systemd[1]: Started istio-auth-node-agent: The Istio auth node agent.
Oct 13 21:32:29 demo-vm-1 node_agent[6941]: I1013 21:32:29.469314    6941 main.go:66] Starting Node Agent
Oct 13 21:32:29 demo-vm-1 node_agent[6941]: I1013 21:32:29.469365    6941 nodeagent.go:96] Node Agent starts successfully.
Oct 13 21:32:29 demo-vm-1 node_agent[6941]: I1013 21:32:29.483324    6941 nodeagent.go:112] Sending CSR (retrial #0) ...
Oct 13 21:32:29 demo-vm-1 node_agent[6941]: I1013 21:32:29.862575    6941 nodeagent.go:128] CSR is approved successfully. Will renew cert in 29m59.137732603s

在網格擴充套件機器上執行服務

  • 配置sidecar來攔截埠。這是在/ var / lib / istio / envoy / sidecar.env中使用ISTIO_INBOUND_PORTS環境變數配置的。示例(在執行該服務的VM上):
    echo "ISTIO_INBOUND_PORTS=27017,3306,8080" > /var/lib/istio/envoy/sidecar.env
    systemctl restart istio
  • 手動配置無選擇者服務和端點。“無選擇者”服務用於不受Kubernetes pods支援的服務。例如,在具有修改Kubernetes服務許可權的機器上:
    # istioctl register servicename machine-ip portname:port
    istioctl -n onprem register mysql 1.2.3.4 3306
    istioctl -n onprem register svc1 1.2.3.4 http:7000

安裝完成後,Kubernetes軟體包和其他網格擴充套件應該能夠訪問機器上執行的服務。

把它放在一起