[純紀錄]Kubernetes基本操作
學習 Kubernetes 與基本操作紀錄
Kubernetes 文章
[Day 6] 實際環境運行的 Kubernetes - Node & Architecture Overview
概觀 Kubernetes 的內部運作Kubernetes 元件介紹與 minikube 安裝教學
pod/Service/Deployment介紹适用于 Docker 用户的 kubectl
提供docker與kubectl指令對應參考[Day 5] 在 Minikube 上跑起你的 Docker Containers - Pod & kubectl 常用指令
pod與yaml說明與如何與 Pod 中的 container 互動Day 4 - 部署應用程式到 Kubernetes 叢集 - Part I - 手動建立 deployment 與 Service
建立deployment 與 Service/nodePort從本地開啟
- Kubernetes —學習好幫手minikube — 01
將K8s所需的Master/Worker node封裝在一個虛擬機器中
https://medium.com/@sniperbean/kubernetes-%E5%AD%B8%E7%BF%92%E5%A5%BD%E5%B9%AB%E6%89%8Bminikube-01-aedfaf8b00fe
kubectl的簡單查看,新增,重開
kubectl的簡單查看,新增,重開
- kubectl get pod -A
kubectl create 建立 後面可以直接加參數或是用yaml來建立
簡單建立deployment
啟動 minikube 之後,我們可以透過 kubectl run 在 minikube 上運行一個 Google 提供的 hello-minikube docker image,1
2
3
4
5$ kubectl create deployment first-deployment --image=katacoda/docker-http-server
deployment.apps/first-deployment created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
first-deployment-8cbf74484-xgc4l 1/1 Running 0 25s建立namespaces
1
2
3
4
5
6
7
8
9
10>kubectl get namespaces
NAME STATUS AGE
default Active 7m52s
kube-node-lease Active 7m53s
kube-public Active 7m53s
kube-system Active 7m53s
//Create a new Namespaces
D:\k8syaml>kubectl create namespace my
namespace/my created建立deployment
https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
D:\k8syaml>kubectl create -f my-first-pod.yaml 編輯要部屬的程式
deployment.apps/my-pod created
查看所有pod
D:\k8syaml>kubectl get pod -A看LOG
kubectl -n NsName logs my-pod-5b788d95bc-kx76k刪除
D:\k8syaml>kubectl delete deployment my-pod -n NsName 先刪除
deployment.apps “my-pod” deleted重開
D:\k8syaml>kubectl -n NsName rollout restart deployment nginx179 執行重開指令
deployment.apps/nginx179 restarted編輯一樣可以達到重開效果
kubectl edit deployment -n NsName nginx179
kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
NsName nginx179-5ddfbfccb8-76qz8 1/1 Running 0 84s//啟動成功
minikube
Kubernetes —學習好幫手minikube — 01
將K8s所需的Master/Worker node封裝在一個虛擬機器中
https://medium.com/@sniperbean/kubernetes-%E5%AD%B8%E7%BF%92%E5%A5%BD%E5%B9%AB%E6%89%8Bminikube-01-aedfaf8b00fe
1.install kubuctl
你可以使用 Kubectl 命令行工具管理 Kubernetes 集群。 kubectl 在 $HOME/.kube 目录中查找一个名为 config 的配置文件。
2.Minikube
Minikube 是由 Google 發布的一個輕量級工具。讓開發者可以在本機上輕易架設一個 Kubernetes Cluster,快速上手 Kubernetes 的指令與環境。Minikube 會在本機上跑起一個 virtual machine,並且在這 VM 裡建立一個 signle-node Kubernetes Cluster,本身並不支援 HA (High availability),也不推薦在實際應用上運行。
安裝:https://minikube.sigs.k8s.io/docs/start/
*開啟docker的k8s設定
docker desktop ->settings->
1 | >kubectl get nodes |
確認kubectl version
1
2
3>kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:51:19Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}server version需要minikube有安裝才會出現
1
2
3
4
5
6
7>kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 3d v1.20.0
PS C:\> minikube dashboard
Opening kubernetes dashboard in default browser...啟動 minikube 之後,我們可以透過 kubectl run 在 minikube 上運行一個 Google 提供的 hello-minikube docker image,
1 | $ kubectl create deployment first-deployment --image=katacoda/docker-http-server |
- 在 minikube 上透過 kubectl get
來自 https://ithelp.ithome.com.tw/articles/10197186
1 | D:\k8syaml>kubectl get namespaces |
建立deployment
1
2
3
4
5
6https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
D:\k8syaml>kubectl create -f my-first-pod.yaml 編輯要部屬的程式
deployment.apps/my-pod created
D:\k8syaml>kubectl get pods
No resources found in default namespace.D:\k8syaml>kubectl get pod -A
1
2
3
4
5
6
7
8
9NAMESPACE NAME READY STATUS RESTARTS AGE
NsName my-pod-5b788d95bc-kx76k 0/1 Error 0 46s 建立不成功因為有相依
kube-system coredns-74ff55c5b-wf484 1/1 Running 0 10m
kube-system etcd-minikube 1/1 Running 0 10m
kube-system kube-apiserver-minikube 1/1 Running 0 10m
kube-system kube-controller-manager-minikube 1/1 Running 0 10m
kube-system kube-proxy-skl6r 1/1 Running 0 10m
kube-system kube-scheduler-minikube 1/1 Running 0 10m
kube-system storage-provisioner 1/1 Running 0 10m看LOG
kubectl -n NsName logs my-pod-5b788d95bc-kx76k
- D:\k8syaml>kubectl delete deployment my-pod -n NS名稱 先刪除
deployment.apps “my-pod” deleted
1 | D:\k8syaml>kubectl get pod -A |
1 | D:\k8syaml>kubectl -n NsName rollout restart deployment nginx179 執行重開指令 |
1 | D:\k8syaml>kubectl apply -f my-web.yaml |
[純紀錄]Kubernetes基本操作