Kubernetes depuis Docker Compose
vol
cm
secret
vol
Présentation créée avec Sozi
t
Bouton
droit
Bouton
gauche
Bouton
du milieu
backend-secret.properties
1
2
pass
=pass123
api_key
=123456789
backend-config.properties
1
2
conf_1
=value1
conf_2
=value2
configmap.yml
1
2
3
4
5
6
7
8
9
10
apiVersion
:
v1
data
:
backend-config.properties
:
|
+
conf_1=value1
conf_2=value2
kind
:
ConfigMap
metadata
:
labels
:
app
:
backend
name
:
backend
secret.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion
:
v1
kind
:
Secret
type
:
Opaque
metadata
:
labels
:
app
:
backend
name
:
backend-29k658kmdk
data
:
backend-secret.properties
:
cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg==
# $ echo -n "cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg==" | base64 -d
# pass=pass123
# api_key=123456789
Comme les configmap mais encodé en base64
Pour les données sensible... accès limité
Mais attention : pas chiffré, juste encodé
Stocke la configuration du service (conteneur),
par clef/valeur.
La valeur pouvant être le contenu d'un fichier
Configmap
Décrit des instances de conteneurs
Permet d'avoir plusieurs réplicas
Permet de faire du rolling update
orchestrer des conteneurs
ing
svc
pod
pod
deploy
(par exemple)
service.yml
1
2
3
4
5
6
7
8
9
10
apiVersion
:
v1
kind
:
Service
metadata
:
name
:
backend
spec
:
ports
:
-
name
:
http
port
:
8080
protocol
:
TCP
targetPort
:
8080
ingress.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion
:
networking.k8s.io/v1
kind
:
Ingress
metadata
:
name
:
backend
annotations
:
kubernetes.io/ingress.class
:
nginx
nginx.ingress.kubernetes.io/rewrite-target
:
/$2
nginx.ingress.kubernetes.io/use-regex
:
"true"
nginx.ingress.kubernetes.io/ssl-redirect
:
"false"
nginx.ingress.kubernetes.io/x-forwarded-prefix
:
/api
spec
:
rules
:
-
http
:
paths
:
-
backend
:
service
:
name
:
backend
port
:
number
:
8080
path
:
/api(/|$)(.*)
pathType
:
ImplementationSpecific
kubectl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash
kubectl
config
get-contexts
kubectl
get
all
--namespace
default
kubectl
get
configmaps
kubectl
scale
--replicas=0
deployment/backend
kubectl
logs
-f
pods/backend-4215bc
kubectl
exec
-it
pods/backend-4215bc
--
sh
kubectl
diff
-f
deployment.yml
kubectl
apply
-f
deployment.yaml
kubectl
delete
-f
deployment.yml
kubectl
diff
-k
.
kubectl
apply
-k
.
kubectl
delete
-k
.
Introduction à Kubernetes
depuis Docker Compose
deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
apiVersion
:
apps/v1
kind
:
Deployment
metadata
:
name
:
backend
spec
:
replicas
:
1
template
:
spec
:
containers
:
-
name
:
backend
image
:
ubuntu:22.04
env
:
-
name
:
POSTGRES_USER
value
:
postgres
ports
:
-
containerPort
:
8080
name
:
http
protocol
:
TCP
volumeMounts
:
-
mountPath
:
/config
name
:
backend-config
-
mountPath
:
/secret
name
:
backend-secret
readinessProbe
:
failureThreshold
:
180
httpGet
:
path
:
/
port
:
80
scheme
:
HTTP
resources
:
requests
:
memory
:
1024Mi
cpu
:
30m
volumes
:
-
name
:
config-vol
configMap
:
name
:
backend
-
name
:
secret-vol
secret
:
secretName
:
backend
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
services
:
backend
:
image
:
ubuntu:22.04
environment
:
POSTGRES_USER
:
postgres
ports
:
-
8080:8080
volumes
:
-
./backend/config:/config
-
./backend/secret:/secret
healthcheck
:
test
:
curl --fail -s http://localhost/
interval
:
10s
timeout
:
5s
retries
:
20
Avec K8S, le cluster est décrit
par différents types d'objets
58 types !
Ces YAML représentent des objets.
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
events ev v1 true Event
limitranges limits v1 true LimitRange
namespaces ns v1 false Namespace
nodes no v1 false Node
persistentvolumeclaims pvc v1 true PersistentVolumeClaim
persistentvolumes pv v1 false PersistentVolume
pods po v1 true Pod
podtemplates v1 true PodTemplate
replicationcontrollers rc v1 true ReplicationController
resourcequotas quota v1 true ResourceQuota
secrets v1 true Secret
serviceaccounts sa v1 true ServiceAccount
services svc v1 true Service
mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition
apiservices apiregistration.k8s.io/v1 false APIService
controllerrevisions apps/v1 true ControllerRevision
daemonsets ds apps/v1 true DaemonSet
deployments deploy apps/v1 true Deployment
replicasets rs apps/v1 true ReplicaSet
statefulsets sts apps/v1 true StatefulSet
tokenreviews authentication.k8s.io/v1 false TokenReview
localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling/v2 true HorizontalPodAutoscaler
cronjobs cj batch/v1 true CronJob
jobs batch/v1 true Job
certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest
leases coordination.k8s.io/v1 true Lease
endpointslices discovery.k8s.io/v1 true EndpointSlice
events ev events.k8s.io/v1 true Event
flowschemas flowcontrol.apiserver.k8s.io/v1beta2 false FlowSchema
prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta2 false PriorityLevelConfiguration
helmchartconfigs helm.cattle.io/v1 true HelmChartConfig
helmcharts helm.cattle.io/v1 true HelmChart
addons k3s.cattle.io/v1 true Addon
ingressclasses networking.k8s.io/v1 false IngressClass
ingresses ing networking.k8s.io/v1 true Ingress
networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy
runtimeclasses node.k8s.io/v1 false RuntimeClass
poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget
clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io/v1 false ClusterRole
rolebindings rbac.authorization.k8s.io/v1 true RoleBinding
roles rbac.authorization.k8s.io/v1 true Role
priorityclasses pc scheduling.k8s.io/v1 false PriorityClass
csidrivers storage.k8s.io/v1 false CSIDriver
csinodes storage.k8s.io/v1 false CSINode
csistoragecapacities storage.k8s.io/v1 true CSIStorageCapacity
storageclasses sc storage.k8s.io/v1 false StorageClass
volumeattachments storage.k8s.io/v1 false VolumeAttachment
sans compter les extensions !
On déclare l'état
désiré du cluster
dans les YAML
qu'on applique
avec kubectl :
- Démo locale
- GCP
Deployment
Mais on peut se concentrer sur 6 seulement
deploy
Deployment
pod
Pod
svc
Service
ing
Ingress
cm
Configmap
secret
Secret
pod
Container
Pod
pod
Container
Container
Pod
node
Node
Cluster
pod
Container
Pod
pod
Container
Container
Pod
pod
Container
Pod
node
Node
pod
Container
Pod
node
Node
Node : serveur physique ou VM sur lequel des pod sont lancés
Pod :
- plus petite unitée déployable,
- groupe de conteneurs partageant les mêmes IP et volumes
- contient souvent qu'un seul conteneur
Routage réseau
vers un service
svc
Service
ing
Ingress
Permet l'accès à un
groupe de pod par un
nom DNS (entre autre)
Pour chaque service,
nous décrivons
plusieurs objets !
Routage
réseau
Configuration
applicative
Gestion des
conteneurs
}
}
}
Auteur: Jérémy Soulary
pod
↓
sur un serveur
↓
sur un cluster de serveurs
(nombre dynamique)
cm
secret
ing
svc
pod
deploy
cm
kustomize-output.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
apiVersion
:
v1
data
:
backend-config.properties
:
|
+
conf_1=value1
conf_2=value2
kind
:
ConfigMap
metadata
:
labels
:
app
:
backend
name
:
backend-228mfttkch
---
apiVersion
:
v1
data
:
backend-secret.properties
:
cGFzcz1wYXNzMTIzCmFwaV9rZXk9MTIzNDU2Nzg5Cg==
kind
:
Secret
metadata
:
labels
:
app
:
backend
name
:
backend-29k658kmdk
type
:
Opaque
---
apiVersion
:
v1
kind
:
Service
metadata
:
labels
:
app
:
backend
name
:
backend
spec
:
ports
:
-
name
:
http
port
:
8080
protocol
:
TCP
targetPort
:
8080
selector
:
app
:
backend
---
apiVersion
:
apps/v1
kind
:
Deployment
metadata
:
labels
:
app
:
backend
name
:
backend
spec
:
replicas
:
1
selector
:
matchLabels
:
app
:
backend
template
:
metadata
:
labels
:
app
:
backend
spec
:
containers
:
-
env
:
-
name
:
POSTGRES_USER
value
:
postgres
image
:
ubuntu:22.04
name
:
backend
ports
:
-
containerPort
:
8080
name
:
http
protocol
:
TCP
readinessProbe
:
failureThreshold
:
180
httpGet
:
path
:
/health
port
:
8080
scheme
:
HTTP
resources
:
requests
:
cpu
:
30m
memory
:
1024Mi
volumeMounts
:
-
mountPath
:
/config
name
:
backend-config
-
mountPath
:
/secret
name
:
backend-secret
volumes
:
-
configMap
:
name
:
backend-228mfttkch
name
:
config-vol
-
name
:
secret-vol
secret
:
secretName
:
backend-29k658kmdk
---
apiVersion
:
networking.k8s.io/v1
kind
:
Ingress
metadata
:
annotations
:
kubernetes.io/ingress.class
:
nginx
nginx.ingress.kubernetes.io/rewrite-target
:
/$2
nginx.ingress.kubernetes.io/ssl-redirect
:
"false"
nginx.ingress.kubernetes.io/use-regex
:
"true"
nginx.ingress.kubernetes.io/x-forwarded-prefix
:
/api
labels
:
app
:
backend
name
:
backend
spec
:
rules
:
-
http
:
paths
:
-
backend
:
service
:
name
:
backend
port
:
number
:
8080
path
:
/api(/|$)(.*)
pathType
:
ImplementationSpecific
Kubernetes depuis Docker Compose
1
Intro+help
orchestrer
docker compose
dcp vs deployment
objet yaml
58 types d'objets K8S
6 types principaux
Cluster
Deployment
Configmap
Secret
Deployment full
Service
Ingress
réseau
pour chaque service
kubectl
démo
vue globale