Tsung-Jung Tsai (TJ_Tsai)
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • 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
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me 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 No publishing access yet

        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.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        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
      • Save as template
      • 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 Create Help
    Create Create new note Create a note from template
    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
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    [雲端] K8s === ###### tags: `雲端 / K8s` ###### tags: `雲端`, `K8s` <br> ![](https://i.imgur.com/vsCp0RX.png)<br><br> [TOC] <br> ## K8s 核心 - [K8s 版本紀錄](https://en.wikipedia.org/wiki/Kubernetes) - [[K8s官網] Production-Grade Container Orchestration](https://kubernetes.io/) - Automated container deployment, scaling, and management 自動化容器佈署、縮放和管理 - [Kubernetes 想解決的問題](https://medium.com/@C.W.Hu/kubernetes-basic-concept-tutorial-e033e3504ec0) (Cheng-Wei Hu | 胡程維) - Kubernetes 想解決的問題是: - 手動部署多個容器到多台機器上,並監測管理這些容器的狀態非常麻煩。 - Kubernetes 要提供的解法: - 提供一個平台以較高層次的抽象化去自動化操作與管理容器們。 <br> ## [K8s 架構](https://ithelp.ithome.com.tw/articles/10202135) ### 架構圖 ![](https://i.imgur.com/PJiPGyb.png) (圖片來源:[15 分鐘學習系列 - 第一次學 Kubernetes 就上手系列](https://ithelp.ithome.com.tw/articles/10202135)) ### K8s - [管理微服務的系統](https://medium.com/@C.W.Hu/kubernetes-helm-chart-tutorial-fbdad62a8b61) - 自動化佈署與管理多台機器上的多個容器 ### etcd - 主要用途 - 儲存 K8s 的所有資料與配置資訊 - [利用 Etcd + Confd + HAProxy 實現服務動態拓展](https://blog.toright.com/posts/posts/5687/利用-etcd-confd-haproxy-實現服務動態拓展.html) - etcd 是一個輕量且分散式的 Key/Value 資料庫 - 亦提供非常簡便的 Rest API 進行操作 ### [scheduler](https://ithelp.ithome.com.tw/articles/10224648?sc=rss.iron) > kube-scheduler就會透過過濾(Filter)與排名(Rank)演算法來計算所有節點的權重,並從中找出一個最佳的節點,接著在 Pod 的.spec.nodeName更新被選取的名稱,然後該狀態會被儲存到 etcd 中。 ### K8s proxy - 負責啟用 K8s 服務的網路規則, 進行網路連線的轉發 ### K8s API 物件 - K8S 的所有資源,都是由 RESTful API 組成 - 每個 K8S 資源,都有唯一的 HTTP 路徑 https://your-k8s.com/api/v1/namespaces/default/pods/my-pod - api: v1 - namespaces: default - pods: my-pod - 這些資源,稱為 K8S 物件 ### namespace - 組織 K8S 資源的個體(可以將它想像成資料夾) ### pod - 9789864768226-Kubernetes:建置與執行 - pod 不是容器 - 容器的群組,K8S 的最小佈署單位 - pod 內的所有容器,都會在同一台機器上 - pod 細節 [<img src="https://i.imgur.com/FGCTfLH.png" style="border : solid 1px black">](https://i.imgur.com/FGCTfLH.png) ### 其他來源的架構圖 ![](https://i.imgur.com/RbH59Ed.png) <br> ## K8s 元件 ### label & annotation - 核心功能 - label 和 annotation 都是 map 元件(key/value 對) - 使用對象 - label 主要是給 k8s 系統用 - annotation 供自動化工具、第三方程式、套件使用 - label - 主要用途 - 作為選擇器(selector),底下是範例: - ```kubectl get pods --selector="key1=value1,key2=values"``` - ```kubectl get deployments --selector="key1=value1"``` - ```kubectl get deployments --show-labels --selector="env in (test, staging)"``` ```kubectl delete deployments --selector="env in (test, staging)"``` - selector 條件內,可搭配不同的運算子 - annotation - 主要用途 - 用來紀錄 「滾動佈署」 的資訊 - 滾動佈署,可以是回復到「較舊的穩定版本」或「升級到新版」 - 次要用途 - 儲存中繼資料,就是儲存額外的資料 - 像是 icon (可以是 url 或是 base64 編碼)、時間戳記等 <br> ## K8S 安裝 > `$ sudo kubeadm reset` > The connection to the server 10.0.x.x:6443 was refused - did you specify the right host or port? - [Install and Deploy Kubernetes on Ubuntu 18.04 LTS ](https://vitux.com/install-and-deploy-kubernetes-on-ubuntu/) :::info :information_source: 備註 - ==已經在 VirtualBox+Ubuntu 18.04 上測試過== - 安裝 kubeadm 套件,該套件會包含 kubectl, kubelet,但沒有 kubernetes-cni ::: - master-node ```bash $ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ... ... Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: kubeadm join 10.0.2.15:6443 --token dt7ex6.honghz54tdfmt0no \ --discovery-token-ca-cert-hash sha256:6439bef11a0e53d670e90aa2dbb3e9a2638ea74f2333bb39512025d551ee1d08 ``` ```shell mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config ``` ```bash $ kubectl get nodes NAME STATUS ROLES AGE VERSION master-node NotReady master 4m35s v1.18.3 ``` ``` $ sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml ``` - slave-node ``` $ sudo kubeadm join 10.0.2.15:6443 --token 291g7y.849nq00zcytbhfbo \ > --discovery-token-ca-cert-hash sha256:467937884013119d1c18d827104e4749aa5105291ea065c38503866d384d9268 ... [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service' [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/ ``` 會出現警告,需要執行 ``` $ systemctl enable docker.service ``` 檢查狀態 ``` $ systemctl status docker ● docker.service - Docker Application Container Engine ``` ### 安裝指定版本的 k8s - [How to install specific version of Kubernetes?](https://stackoverflow.com/questions/49721708/how-to-install-specific-version-of-kubernetes) ``` apt-get install -qy kubeadm=<version> ``` 列出所有 k8s 版本 ``` curl -s https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/Packages | grep Version | awk '{print $2}' ``` <br> ## K8S 生態 ### k8s-iceberg https://flant.com/media/k8s-iceberg.svg ![](https://i.imgur.com/xMmuhnr.png) ![](https://i.imgur.com/RccNMk5.png) <br> ## 其他指令 <br> ## CNCF 認證 - #### 官網 - [Certified Kubernetes Administrator (CKA) Program](https://www.cncf.io/certification/cka/) - #### 學習資源 - [CKA(Certified Kubernetes Administrator) 學習資源整理](https://godleon.github.io/blog/Kubernetes/k8s-CKA-resources/) - #### 心得 - [【CKA認證】如何參加CKA考試及學習考試心得](https://www.itread01.com/content/1540972513.html) - [CKA考試經驗總結](https://www.jishuwen.com/d/priZ/zh-tw) - [「附經驗」一個傳統IT運維人的CKA認證之旅](https://kknews.cc/zh-tw/news/p9nz9l8.html) > Concepts文檔講述了每一種Kubernetes編排對象的概念、YAML文件示例和使用方法,你可以把常見編排對象的YAML文件格式收藏在Chrome瀏覽器書籤中,這樣考試的時候可以輕鬆查找,不用再費勁去kubernetes.io網站搜索了。 - [CNCF基金會的Certified Kubernetes Administrator認證考試計劃_Kubernetes中文社群](https://www.itread01.com/content/1545851161.html) - [【從題目中學習k8s】-【後記】CKA證照](https://ithelp.ithome.com.tw/articles/10253064) - [【從題目中學習k8s】-【Day1】K8s初探](https://ithelp.ithome.com.tw/articles/10234562) <br> ## with Spark - [Spark on Kubernetes for Qcon_rev](https://www.slidestalk.com/u86/SparkonKubernetesforQcon_rev213672) - [以 Kubernetes 部屬 Spark 大數據計算環境](https://www.slideshare.net/inwinstack/kubernetes-spark) <br> <br> ## trouble-shooting - [What does the "ctl" in "kubectl" stand for?](https://www.quora.com/What-does-the-ctl-in-kubectl-stand-for) > “ctl” stands for control. There are a few pronunciations we’ve come across for kubectl: “kube control”, “kube cuddle”, “kube c-t-l”, or “kubie cuttle”. (We prefer “kube c-t-l” at ReactiveOps.) - The connection to the server localhost:8080 was refused ``` $ kubectl get cs The connection to the server localhost:8080 was refused - did you specify the right host or port? ``` - 尚未呼叫 ``` $ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ``` - [Troubleshooting kubectl Error: The connection to the server x.x.x.x:6443 was refused – did you specify the right host or port?](https://www.thegeekdiary.com/troubleshooting-kubectl-error-the-connection-to-the-server-x-x-x-x6443-was-refused-did-you-specify-the-right-host-or-port/) ``` $ sudo firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: ssh dhcpv6-client ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: ``` - [How to Fix “firewall-cmd: command not found” Error in RHEL/CentOS 7](https://www.tecmint.com/fix-firewall-cmd-command-not-found-error/) ```$ sudo yum install firewalld``` - [[wiki] Firewalld](https://zh.wikipedia.org/wiki/Firewalld) ```$ sudo firewall-cmd --state``` - firewalld: firewall daemon <br> - Unable to connect to the server: net/http: TLS handshake timeout ```bash $ kubectl get nodes Unable to connect to the server: net/http: TLS handshake timeout ``` - 原因不明,可能的解法如下: - [Suddenly getting “Unable to connect to the server: net/http: TLS handshake timeout” from kubectl](https://stackoverflow.com/questions/54264421/suddenly-getting-unable-to-connect-to-the-server-net-http-tls-handshake-timeo) <br> ## K8s 使用情境緣由 - [【Podcast】Kubernetes vs Serverless with Matt Ward - Software Engineering Daily](https://nijialin.com/2020/07/05/podcast-kuernetes-vs-serverless/) <br> ## 參考資料 - [GKE 系列文章(一) – 為什麼使用 Kubernetes](https://blog.gcp.expert/kubernetes-gke-introduction/) ![](https://i.imgur.com/07Ww4Cv.png) > 但是Docker容器不是萬能,在容器/服務個數越來越複雜的情況下,如何管理叢集和服務的生命週期,將會是各家容器編排管理(orchestration)的能力。其中Google的Kubernetes就是一個十分精良的容器編排管理工具。 - [GKE 系列教學 (二) – 簡介Pod的網路機制](https://blog.gcp.expert/gke-k8s-pod-network/) - K8s v.s. GKE <img style="border: 1px solid" src="https://i.imgur.com/QTxbZfL.png"> - GKE - K8s 託管服務,一次設定,終生託管。 - 5個節點(含)以下,免管理費;6個節點(含)以上,每月台幣約3000元(109.5美元) <br> - [service 如何解釋](https://medium.com/@C.W.Hu/kubernetes-implement-ingress-deployment-tutorial-7431c5f96c3e) > 用來定義「一群 Pod 要如何被連線及存取」的元件 > - [Kubernetes 基礎教學(二)實作範例:Pod、Service、Deployment、Ingress](https://medium.com/@C.W.Hu/kubernetes-implement-ingress-deployment-tutorial-7431c5f96c3e) ``` ## K8s 的勉勵 - 2020/11/20 - [矽谷牛的耕田筆記 - 跟大家分享一個熱騰騰的消息,來自於 CNCF 上面 Apple Inc 的分享 Apple...](https://m.facebook.com/story.php?story_fbid=161171765716964&id=110694344098040) - 2021/01/03 - [2021加速轉型9大趨勢(三)K8s終於通吃跨雲落地各平臺,將成IT現代化主流標準](https://www.ithome.com.tw/news/141975)

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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