# Kubernetes & managment by rancher k8s 單位結構  * 左架構圖雖然乍看複雜,但其實中只要認識其中幾個基本的元件: * Cluster:由紫色 Master 來管理底下橘色的 Node。 * Pod:對 Container 再一次封裝,之後如果要 Scale,就會自動新增刪減 Pod,是 Immutable deploy 的最小單位。 * Service:Pod 運行後需要透過定義 Service 才能讓外部的使用者訪問。 ## Introduction ### k8s 維護與管理 1. 對於k8s CSI, CRI,CNI 認識,內部元件溝通方式 2. 熟悉 rancher 與 kubectl 於k8s 使用 ### 1.CSI, CRI,CNI  * CRI(Container Runtime Interface) * CNI(Container Network Interface) * CSI(Container Storage Interface) ## 2.k8s cluster 內部元件關聯  * control panel(master) * kube-apiserver :k8s 的入口,各其他元件通訊時都需要提供/驗證對應的憑證(客戶端/服務端) * etcd : k8s 資源的 DB * kube-scheduler : cluster 的預設調度器 * kube-controller-manager : 即 Kubernetes 隨附的控制器包括 Replicaset Controller、Node Controller、Namespace Controller 和 ServiceAccount Controller等 * worker node * kubelet :透過apiserver 對 pod ,node 指令操作介面 * kube-proxy ### kubectl `kubectl [command] [TYPE] [NAME] [flags]` * command ex:create、get、describe、delete * TYPE 指定資源型別 ex: pod, ingress... * NAME 資源的名稱 ex: pod名字 * flags 可選的參數 ex: -s 或 --server #### 常用 ``` kubectl config SUBCOMMAND [flags] apply apply -f FILENAME [flags] cluster-info [flags] cordon NODE [options] create -f FILENAME [flags] delete delete (-f FILENAME | TYPE [NAME | /NAME | -l label | --all]) [flags] describe (-f FILENAME | TYPE [NAME_PREFIX | /NAME | -l label]) [flags] get (-f FILENAME | TYPE [NAME | /NAME | -l label]) [--watch] [--sort-by=FIELD] [[-o | --output]=OUTPUT_FORMAT] [flags] edit (-f FILENAME | TYPE NAME | TYPE/NAME) [flags] exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]] logs kubectl logs POD [-c CONTAINER] [--follow] [flags] ``` #### 備忘錄: ``` # get kubectl get nodes kubectl get services kubectl get pods --all-namespaces kubectl get pods -o wide kubectl get deployment my-dep kubectl get pods kubectl get pod my-pod -o yaml # config kubectl config view # apply kubectl apply -f ./my-manifest.yaml kubectl apply -f ./my1.yaml -f ./my2.yaml kubectl apply -f ./dir kubectl apply -f https://git.io/vPieo kubectl create deployment nginx --image=nginx kubectl apply -f - <<EOF apiVersion: v1 kind: Pod metadata: name: busybox-sleep spec: containers: - name: busybox image: busybox:1.28 args: - sleep - "1000000" --- apiVersion: v1 kind: Pod metadata: name: busybox-sleep-less spec: containers: - name: busybox image: busybox:1.28 args: - sleep - "1000" EOF ```  ## How to build a service by Rancher ? * Rancher : k8s web UI management platform * Deployment : setting pod info * Service: corresponding port with pod * Ingress: corresponding service and port to internet ## Deployment #### Deployment > create Pod  #### For example 1. Pod lable 2. Pod staorage 3. Container image  ##### About **storage** setting  ``` Pod Storage 部分,如果有要掛 volumn 或是調整 config 請在這邊掛。 外掛可編輯的文件檔 用 configmap 掛 空間可以用 PVC ``` #### About **container** setting  ## Service Service Discovery > Services    ## Ingress Service Discovery > Ingress  ## Configmaps 
×
Sign in
Email
Password
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