Kubernetes Summit
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 體驗 Istio 強大的 Service Mesh 能力 {%hackmd @k8ssummit/HJIAQ-0VP %} 這是 [Will 保哥](https://www.facebook.com/will.fans) 在 [Kubernetes Summit 2020](https://k8s.ithome.com.tw/) 實戰工作坊 [體驗 Istio 強大的 Service Mesh 能力](https://k8s.ithome.com.tw/hol#workshop1) 的課前準備文件。請有意參加這場實戰工作坊的朋友,請務必事先安裝好實作環境! **回報實作進度**: https://github.com/doggy8088/IstioHOL/issues ## 課前準備 ### 前置條件 (Prerequisites) 本次實戰工作坊需要學員參考本篇文章進行環境設定,以確保實作順利: - Windows - 作業系統:Windows 10 版本 2004 (Build 19041) 以上 - 安裝 [Docker Desktop for Windows](https://hub.docker.com/editions/community/docker-ce-desktop-windows) 穩定版本 (Stable) - 請先安裝好 [Chocolatey](https://chocolatey.org/install) 套件管理器 - 啟用 WSL 2 功能 (Optional) - 請記得透過 `wsl.exe --set-default-version 2` 將之後安裝的 Distro 預設都調整為 WSL 2 版本 - 官方文件: [Windows Subsystem for Linux Installation Guide for Windows 10](https://docs.microsoft.com/en-us/windows/wsl/install-win10) - 可以參考 [使用 WSL 2 打造優質的多重 Linux 開發環境](https://blog.miniasp.com/post/2020/07/26/Multiple-Linux-Dev-Environment-build-on-WSL-2) 文章進行調整環境 - 到 **Microsoft Store** 安裝 [Ubuntu 20.04 LTS](https://www.microsoft.com/zh-tw/p/ubuntu-2004-lts/9n6svws3rx71) 應用程式 - macOS - 作業系統:10.13 以上版本 (Catalina, Mojave, or High Sierra) - 安裝 [Docker Desktop on Mac](https://docs.docker.com/docker-for-mac/install/) 穩定版本 (Stable) - 請先安裝好 [Homebrew](https://brew.sh/index_zh-tw) 套件管理器 ### 安裝 [KinD](https://kind.sigs.k8s.io/) 命令列工具 - On Mac (homebrew) ```sh brew install kind ``` - On Windows 使用 [Chocolatey](https://chocolatey.org/install) 安裝 [Kind](https://chocolatey.org/packages/kind) 套件 ```sh choco install kind -y ``` 如果你已經安裝過 [Docker Desktop for Windows](https://hub.docker.com/editions/community/docker-ce-desktop-windows) 的話,請改用以下命令安裝: ```sh choco install kind -i -y ``` 也可透過 PowerShell 下載 Windows 執行檔 ```ps1 curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.9.0/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe ``` - On Linux ```sh curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind ``` - 驗證安裝版本 ```sh kind --version ``` > ```txt >kind version 0.9.0 > ``` ### 安裝 Kubectl 命令列工具 - On Mac (homebrew) ```sh brew install kubectl ``` - On Windows ```sh choco install kubernetes-cli -y ``` - On Linux ```sh curl -sLO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl ``` - 驗證安裝版本 ```sh kubectl version --client --short ``` > ```txt > Client Version: v1.19.1 > ``` ### 安裝 kubectx 與 kubens 工具 - 安裝 [kubectx 與 kubens](https://github.com/ahmetb/kubectx) 工具 ```sh sudo apt install pkg-config -y wget https://github.com/ahmetb/kubectx/releases/download/v0.9.1/kubectx_v0.9.1_linux_x86_64.tar.gz wget https://github.com/ahmetb/kubectx/releases/download/v0.9.1/kubens_v0.9.1_linux_x86_64.tar.gz sudo tar zxvf kubectx_v0.9.1_linux_x86_64.tar.gz -C /usr/local/bin kubectx sudo tar zxvf kubens_v0.9.1_linux_x86_64.tar.gz -C /usr/local/bin kubens sudo git clone https://github.com/ahmetb/kubectx.git /etc/kubectx COMPDIR=$(pkg-config --variable=completionsdir bash-completion) sudo ln -sf /etc/kubectx/completion/kubens.bash $COMPDIR/kubens sudo ln -sf /etc/kubectx/completion/kubectx.bash $COMPDIR/kubectx rm kubectx_v0.9.1_linux_x86_64.tar.gz kubens_v0.9.1_linux_x86_64.tar.gz ``` ### 安裝 k9s 工具 - 安裝 k9s 工具 ```sh wget https://github.com/derailed/k9s/releases/download/v0.21.7/k9s_Linux_x86_64.tar.gz sudo tar -zxvf k9s_Linux_x86_64.tar.gz -C /usr/local/bin k9s ``` - 驗證安裝版本 ```sh k9s info ``` ### 建立 KinD 叢集 建立一個有 1 個 control-plane nodes 與 1 個 worker nodes 的 [KinD](https://kind.sigs.k8s.io/docs/user/quick-start/) 叢集: 1. 先建立 `kind-2nodes.yaml` 檔案 ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker extraPortMappings: - containerPort: 30080 hostPort: 80 - containerPort: 30443 hostPort: 443 - containerPort: 32034 hostPort: 32034 - containerPort: 30291 hostPort: 30291 - containerPort: 31538 hostPort: 31538 - containerPort: 31952 hostPort: 31952 - containerPort: 31813 hostPort: 31813 ``` 2. 建立叢集 ```sh kind create cluster --config ./kind-2nodes.yaml ``` 3. 如果你從 Windows 建立叢集,但想在 WSL 2 操作 kubectl 的話,請執行以下命令: ```sh kind export kubeconfig ``` 4. 測試 kubectl 叢集連線 ```sh kubectl cluster-info kubectl get nodes ``` ```log $ kubectl cluster-info Kubernetes master is running at https://127.0.0.1:25783 KubeDNS is running at https://127.0.0.1:25783/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. $ kubectl get nodes NAME STATUS ROLES AGE VERSION kind-control-plane Ready master 22m v1.19.1 kind-worker Ready <none> 21m v1.19.1 ``` ### 測試 Kubernetes 與 Networking 可否正常運作 1. 建立 `mynginx.yaml` 檔案 ```sh cat <<EOF > mynginx.yaml apiVersion: v1 kind: Service metadata: name: web-nginx labels: app.kubernetes.io/name: nginx spec: type: NodePort ports: - name: http port: 80 targetPort: http nodePort: 30080 selector: app.kubernetes.io/name: nginx --- apiVersion: apps/v1 kind: Deployment metadata: name: web-nginx labels: app.kubernetes.io/name: nginx spec: selector: matchLabels: app.kubernetes.io/name: nginx replicas: 2 template: metadata: labels: app.kubernetes.io/name: nginx spec: containers: - name: nginx image: docker.io/bitnami/nginx:1.19.1-debian-10-r23 ports: - name: http containerPort: 8080 EOF ``` 2. 建立 mynginx 服務 ```sh kubectl apply -f mynginx.yaml ``` 3. 測試服務連線是否正常 <http://localhost/> ![Welcome to nginx!](https://user-images.githubusercontent.com/88981/93754527-79316280-fc34-11ea-86f7-ffacf3d4a08e.png) 4. 移除 mynginx 服務 ```sh kubectl delete -f ./mynginx.yaml ``` ## Istio 新手上路 ### 安裝 Istio 服務 1. 下載 [Istio](https://istio.io/) ```sh curl -sL https://istio.io/downloadIstio | sh - cd istio-1.* export PATH=$PWD/bin:$PATH ``` ```log Downloading istio-1.7.2 from https://github.com/istio/istio/releases/download/1.7.2/istio-1.7.2-linux-amd64.tar.gz ... Istio 1.7.2 Download Complete! Istio has been successfully downloaded into the istio-1.7.2 folder on your system. Next Steps: See https://istio.io/latest/docs/setup/install/ to add Istio to your Kubernetes cluster. To configure the istioctl client tool for your workstation, add the /home/will/build/istio-1.7.2/bin directory to your environment path variable with: export PATH="$PATH:/home/will/build/istio-1.7.2/bin" Begin the Istio pre-installation check by running: istioctl x precheck Need more information? Visit https://istio.io/latest/docs/setup/install/ ``` 2. 安裝 Istio 之前的檢查 ```sh istioctl x precheck ``` 3. 安裝 Istio 服務 ([Installation Guides](https://istio.io/latest/docs/setup/install/)) 我們將用 [Install with Istioctl](https://istio.io/latest/docs/setup/install/istioctl/) 文件的說明進行安裝。 測試環境可以用 `demo` 這個 Profile 來進行安裝,但正式環境不建議使用 `demo` Profile 喔! ```sh istioctl install --set profile=demo ``` > 更多 Profile 請參考 [Installation Configuration Profiles](https://istio.io/latest/docs/setup/additional-setup/config-profiles/) 文件。 4. 設定 `default` 這個 namespace 啟用自動注入 Sidecar 的 Label ```sh kubectl label namespace default istio-injection=enabled ``` 列出目前所有 namespace 的 `istio-injection` 狀態 ```sh kubectl get namespace -L istio-injection ``` 5. 部署 Istio 範例應用程式 (`bookinfo`) ```sh kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml kubectl get services kubectl get pods kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>" ``` 6. 開放應用程式給外部網路連線 ```sh kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml ``` 驗證 Istio 設定是否正確 (因為太容易設定錯誤了,特別寫了一個工具專門用來檢查) ```sh istioctl analyze ``` 7. 決定 ingress 的 IP 與 Ports 先取得 `istio-system` 負責對外的 `istio-ingressgateway` 服務資訊 ```sh kubectl get svc istio-ingressgateway -n istio-system ``` 由於 KinD 內的服務沒辦法透過 `type: LoadBalancer` 取得 IP 地址,因此必須手動改成 `type: NodePort` 才行! > [Service | Kubernetes > Type NodePort](https://kubernetes.io/docs/concepts/services-networking/service/#nodeport) 請修改 `spec.type` 為 `NodePort`,並調整 `.spec.ports[*].nodePort` 的 Port 埠號。 - 將 `name: http2` 的 `nodePort` 調整為 `30080` - 將 `name: https` 的 `nodePort` 調整為 `30443` 8. 在 Windows 10 開啟瀏覽器,透過 Istio Gateway 瀏覽網頁! 當你連到 <http://localhost/> 將會看到 HTTP 404 錯誤頁面。 當你連到 <http://localhost/productpage> 就會看到 BookInfo Sample 的首頁! 重新整理 <http://localhost/productpage> 網頁可以看到不同的 **Book Reviews** 內容(來自不同的 Pod 執行結果) ## 服務監控 ### 安裝 Grafana 與 Prometheus 服務 1. 安裝 [Grafana](https://istio.io/latest/docs/ops/integrations/grafana/) 與 [Prometheus](https://istio.io/latest/docs/ops/integrations/prometheus/) ```sh kubectl apply -f samples/addons/prometheus.yaml -f samples/addons/grafana.yaml ``` 2. 開啟 Grafana dashboard 查看 Istio 相關監控數據 透過以下命令可以啟動一個 Proxy 端點,讓你可以透過本機進行瀏覽 > 請注意:每次執行 `istioctl dashboard` 可能會產生不同的 Ports ```sh $ istioctl dashboard grafana http://localhost:3000 Failed to open browser; open http://localhost:3000 in your browser. ``` ![istio / Istio Control Plane Dashboard](https://user-images.githubusercontent.com/88981/93773470-c6243180-fc52-11ea-8e4e-54b858dae92a.png) 3. 壓力測試 ```sh kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- bash curl -s productpage:9080/productpage | grep -o "<title>.*</title>" ``` ```sh while true; do curl -s productpage:9080/productpage | grep -o "<title>.*</title>"; done ``` ## 流量監控 ### 安裝 Kiali 服務 1. 安裝 [Kiali](https://istio.io/latest/docs/ops/integrations/kiali/) 為 Istio Addons ```sh kubectl apply -f samples/addons/kiali.yaml ``` > 如果執行時有出現錯誤訊息,請重新執行一遍。 2. 開啟 Kiali dashboard 查看 Istio 的所有流量資訊 透過以下命令可以啟動一個 Proxy 端點,讓你可以透過本機進行瀏覽 > 請注意:每次執行 `istioctl dashboard kiali` 可能會產生不同的 Ports ```sh $ istioctl dashboard kiali http://localhost:20001/kiali Failed to open browser; open http://localhost:20001/kiali in your browser. ``` 參考下圖進行報表顯示設定,對網站進行壓力測試後,就會看見流量的即時動畫! ![Kiali Console - Graph](https://user-images.githubusercontent.com/88981/90917039-aeb81580-e414-11ea-9bb2-210c762abc26.png) 3. 壓力測試 ```sh kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- bash curl -s productpage:9080/productpage | grep -o "<title>.*</title>" ``` ```sh while true; do curl -s productpage:9080/productpage | grep -o "<title>.*</title>"; done ``` ## 清空資源 ### 移除 bookinfo 應用程式 ```sh kubectl delete -f samples/bookinfo/platform/kube/bookinfo.yaml ``` ### 移除 Istio 安裝 ```sh kubectl label namespace default istio-injection- kubectl get namespace -L istio-injection istioctl x uninstall --purge kubectl delete namespace istio-system ``` ### 刪除 kind 叢集 ```sh kind delete cluster ``` ###### tags: `k8ssummit20` `k8s`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully