Replicaset e Deployment
Creazione di Pod
In modalità dichiarativa.
Creare una directory per l’esercizio:
mkdir -p ~/kube/hello
cd ~/kube/hello
File di specifiche per il pod:
vim pod.yml
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
zone: prod
version: v1
spec:
containers:
- name: hello-ctr
image: nigelpoulton/k8sbook:latest
ports:
- containerPort: 8080
Creazione del pod:
kubectl create -f pod.yml
IL pronto torna subito ma il comando per completare impiegherà tempo, poichè vi è un’immagine da scaricare.
Ispezione del comando in esecuzione:
kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 0/1 ContainerCreating 0 52s
Ispezione più dettagliata:
kubectl describe pods hello-pod
Dopo qualche tempo:
kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 1/1 Running 0 7m29s
Creare un ReplicaSet
File di specifiche:
vim rs.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: web-rs
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-ctr
image: nigelpoulton/k8sbook:latest
ports:
- containerPort: 8080
Creare il ReplicaSet:
kubectl create -f rs.yml
replicaset.apps/web-rs created
Notare il nome dell'oggetto, composto di due parti separate da ‘/’
Si può citare il nome completo nei comandi.
Per i replicasets l’alias di 'replicaset.apps' è anche ‘rs’.
Listare il ReplicaSet:
kubectl get replicaset.apps/web-rs
kubectl get rs/web-rs
Listare tutti i pods e le loro labels:
kubectl get pods --show-labels
Scala di un ReplicaSet
Nel file di configurazione rs.yml
, cambiamo il parametro replicas da 3 a 5.
Sottoponiamo il cambiamento:
kubectl apply -f rs.yml
Otteniamo un warning:
Warning: resource replicasets/web-rs is missing the
kubectl.kubernetes.io/last-applied-configuration annotation
which is required by kubectl apply. kubectl apply should only
be used on resources created declaratively by either
kubectl create --save-config or kubectl apply.
The missing annotation will be patched automatically.
Il warning compare solo la prima volta.
Verificare:
kubectl get rs/web-rs
kubectl get pods --show-labels
Nota:
- Se si adotta il formato dichiarativo occorre astenersi dall’uso di comandi imperativi sugli oggetti creati
- Potrebbe causare disallineamenti