Solution TP 7

/images/k8s.jpeg

TP7 : Multi env w/ Namespace

Namespace

🇫🇷 Version Française

Manifest du namespace :

1apiVersion: v1
2kind: Namespace
3metadata:
4  name: form-k8s-acc
5  labels:
6    env: acc

Ajout de namespace: form-k8s-acc dans toutes les ressources créé précédemment juste n dessous de “name” dans le block metadata (ligne 3 de chaque fichier)

exemple pour le secret backend (ligne 5) :

1apiVersion: v1
2kind: Secret
3metadata:
4  name: back-secret
5  namespace: form-k8s-acc
6type: Opaque
7data:
8  MONGO_USERNAME: QWRtaW4=
9  MONGO_PASSWORD: UGFzc3dvcmQ=

Ingress

L’ingress va maintenant répondre sur un subpath donc toutes les régles vont nécéssiter un “rewrite-target”, on peut donc maintenant ramener la configuration de nos ingress dans un seul manifest :

 1apiVersion: networking.k8s.io/v1
 2kind: Ingress
 3metadata:
 4  name: app-ingress-front
 5  namespace: form-k8s-acc
 6  annotations:
 7    nginx.ingress.kubernetes.io/rewrite-target: /$1
 8spec:
 9  rules:
10    - http:
11        paths:
12          - path: /acc/(.*)
13            pathType: ImplementationSpecific
14            backend:
15              service:
16                name: front-training-app
17                port:
18                  number: 80
19          - path: /acc/api/(.*)
20            pathType: ImplementationSpecific
21            backend:
22              service:
23                name: back-training-app
24                port:
25                  number: 80
🇬🇧 English version

Namespace manifest :

1apiVersion: v1
2kind: Namespace
3metadata:
4  name: form-k8s-acc
5  labels:
6    env: acc

Added namespace: form-k8s-acc in all previously created resources just below “name” in the metadata block (line 3 of each file)

example for the backend secret (line 5):

1apiVersion: v1
2kind: Secret
3metadata:
4  name: back-secret
5  namespace: form-k8s-acc
6type: Opaque
7data:
8  MONGO_USERNAME: QWRtaW4=
9  MONGO_PASSWORD: UGFzc3dvcmQ=

Ingress

The ingress will now respond on a subpath so all the rules will require a “rewrite-target”, so we can now bring the configuration of our ingress into a single manifest:

 1apiVersion: networking.k8s.io/v1
 2kind: Ingress
 3metadata:
 4  name: app-ingress-front
 5  namespace: form-k8s-acc
 6  annotations:
 7    nginx.ingress.kubernetes.io/rewrite-target: /$1
 8spec:
 9  rules:
10    - http:
11        paths:
12          - path: /acc/(.*)
13            pathType: ImplementationSpecific
14            backend:
15              service:
16                name: front-training-app
17                port:
18                  number: 80
19          - path: /acc/api/(.*)
20            pathType: ImplementationSpecific
21            backend:
22              service:
23                name: back-training-app
24                port:
25                  number: 80

Latest Posts