Kubernetes入門
Frank Heilmann
Platform Architect and Freelance Instructor
kubectl: Kubernetes オブジェクト操作の主要コマンドpod、service など$$
代表的な使い方:
kubectl create -f <Manifest.yml>: 新規作成(-f はファイル指定)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、template を定義selector は後述template は Deployment が作る Pod の詳細を記述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> で Pod を作成し、変更を反映Kubernetes入門