Kubernetes 入門
Frank Heilmann
Platform Architect and Freelance Instructor
kubectl:與 Kubernetes 物件互動的主要指令pod、service 等$$
常見用法:
kubectl create -f <Manifest.yml>:建立新物件,-f 表示「filename」kubectl apply -f <Manifest.yml>:建立新物件並
變更物件狀態kubectl get <object>:
檢視叢集中已部署物件的總覽kubectl describe <object>:取得物件的詳細資訊$$
可用指令列選項 --help 取得詳細說明
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25.4
ports:
- containerPort: 80
無狀態應用:
一旦中斷,會重建新的副本並繼續運作。
apiVersion 與 kindmetadata 與 specspec 會定義 replicas 數量、selector,以及 templateselector 後面會再介紹template 描述在 Deployment 中建立 pods 的細節apiVersion: apps/v1
kind: Deployment
metadata:
name: <deployment name>
labels:
app: <a label for the application>
spec:
replicas: <number of initial replicas>
selector:
matchLabels:
app: <matches the label above>
template:
metadata:
labels:
app: <label to be given to each pod>
spec:
containers:
- name: <container name>
image: <the image to be used>
ports:
- containerPort: <ports for networking>
kubectl apply -f <manifest.yml> 來建立 pods 並
套用變更。Kubernetes 入門