@@ -41,7 +41,7 @@ The programming language of the project is KCL, not JSON/YAML which Kubernetes r
4141Enter stack dir ` examples/appops/nginx-example/dev ` and compile:
4242
4343``` bash
44- cd examples/appops/nginx-example/dev && kcl run -D env =dev
44+ cd examples/appops/nginx-example/dev && kcl run -D appenv =dev
4545```
4646
4747The output YAML is:
@@ -50,71 +50,71 @@ The output YAML is:
5050apiVersion : apps/v1
5151kind : Deployment
5252metadata :
53- name : sampleappdev
54- namespace : sampleapp
53+ name : sampleapp-dev
54+ namespace : sampleappns-dev
5555spec :
5656 replicas : 1
5757 selector :
5858 matchLabels :
5959 app.kubernetes.io/name : sampleapp
6060 app.kubernetes.io/env : dev
6161 app.kubernetes.io/instance : sampleapp-dev
62- app.k8s.io/component : sampleappdev
62+ app.k8s.io/component : sampleapp-dev
6363 template :
6464 metadata :
6565 labels :
6666 app.kubernetes.io/name : sampleapp
6767 app.kubernetes.io/env : dev
6868 app.kubernetes.io/instance : sampleapp-dev
69- app.k8s.io/component : sampleappdev
69+ app.k8s.io/component : sampleapp-dev
7070 spec :
7171 containers :
72- - env :
73- - name : MY_ENV
74- value : MY_VALUE
75- image : nginx:1.7.8
76- name : main
77- ports :
78- - containerPort : 80
79- protocol : TCP
80- resources :
81- limits :
82- cpu : " 100m"
83- memory : " 100Mi"
84- ephemeral-storage : " 1Gi"
85- requests :
86- cpu : " 100m"
87- memory : " 100Mi"
88- ephemeral-storage : " 1Gi"
89- volumeMounts : []
72+ - env :
73+ - name : MY_ENV
74+ value : MY_VALUE
75+ image : nginx:1.7.8
76+ name : main
77+ ports :
78+ - containerPort : 80
79+ protocol : TCP
80+ resources :
81+ limits :
82+ cpu : ' 100m'
83+ memory : ' 100Mi'
84+ ephemeral-storage : ' 1Gi'
85+ requests :
86+ cpu : ' 100m'
87+ memory : ' 100Mi'
88+ ephemeral-storage : ' 1Gi'
89+ volumeMounts : []
9090---
9191apiVersion : v1
9292kind : Namespace
9393metadata :
94- name : sampleapp
94+ name : sampleappns-dev
9595---
9696apiVersion : v1
9797kind : Service
9898metadata :
9999 name : nginx
100- namespace : sampleapp
100+ namespace : sampleappns-dev
101101spec :
102102 ports :
103- - nodePort : 30201
104- port : 80
105- targetPort : 80
103+ - nodePort : 30201
104+ port : 80
105+ targetPort : 80
106106 selector :
107107 app.kubernetes.io/name : sampleapp
108108 app.kubernetes.io/env : dev
109109 app.kubernetes.io/instance : sampleapp-dev
110- app.k8s.io/component : sampleappdev
110+ app.k8s.io/component : sampleapp-dev
111111 type : NodePort
112112` ` `
113113
114114After compiling, we can see three resources:
115115
116- - A ` Deployment` with the name `sampleappprod `
117- - A `Namespace` with the name `sampleapp `
116+ - A ` Deployment` with the name `sampleapp-dev `
117+ - A `Namespace` with the name `sampleappns-dev `
118118- A `Service` with the name `nginx`
119119
120120# ## 2. Modification
@@ -131,71 +131,72 @@ The `image` attribute in the `Server` model is used to declare the application's
131131Recompile the configuration code to obtain the modified YAML output :
132132
133133` ` ` shell
134- kcl run
134+ kcl run -D appenv=dev
135135` ` `
136136
137137` ` ` yaml
138138apiVersion: apps/v1
139139kind: Deployment
140140metadata:
141- name: sampleappdev
142- namespace: sampleapp
141+ name: sampleapp-dev
142+ namespace: sampleappns-dev
143143spec:
144144 replicas: 1
145145 selector:
146146 matchLabels:
147147 app.kubernetes.io/name: sampleapp
148148 app.kubernetes.io/env: dev
149149 app.kubernetes.io/instance: sampleapp-dev
150- app.k8s.io/component: sampleappdev
150+ app.k8s.io/component: sampleapp-dev
151151 template:
152152 metadata:
153153 labels:
154154 app.kubernetes.io/name: sampleapp
155155 app.kubernetes.io/env: dev
156156 app.kubernetes.io/instance: sampleapp-dev
157- app.k8s.io/component: sampleappdev
157+ app.k8s.io/component: sampleapp-dev
158158 spec:
159159 containers:
160- - env:
161- - name: MY_ENV
162- value: MY_VALUE
163- image: nginx:latest
164- name: main
165- ports:
166- - containerPort: 80
167- protocol: TCP
168- resources:
169- limits:
170- cpu: " 100m"
171- memory: " 100Mi"
172- ephemeral-storage: " 1Gi"
173- requests:
174- cpu: " 100m"
175- memory: " 100Mi"
176- ephemeral-storage: " 1Gi"
177- volumeMounts: []
160+ - env:
161+ - name: MY_ENV
162+ value: MY_VALUE
163+ image: nginx:1.7.8
164+ name: main
165+ ports:
166+ - containerPort: 80
167+ protocol: TCP
168+ resources:
169+ limits:
170+ cpu: ' 100m'
171+ memory: ' 100Mi'
172+ ephemeral-storage: ' 1Gi'
173+ requests:
174+ cpu: ' 100m'
175+ memory: ' 100Mi'
176+ ephemeral-storage: ' 1Gi'
177+ volumeMounts: []
178178---
179179apiVersion: v1
180180kind: Namespace
181181metadata:
182- name: sampleapp
182+ name: sampleappns-dev
183183---
184184apiVersion: v1
185185kind: Service
186186metadata:
187187 name: nginx
188- namespace: sampleapp
188+ namespace: sampleappns-dev
189189spec:
190190 ports:
191- - nodePort: 30201
192- port: 80
193- targetPort: 80
191+ - nodePort: 30201
192+ port: 80
193+ targetPort: 80
194194 selector:
195195 app.kubernetes.io/name: sampleapp
196196 app.kubernetes.io/env: dev
197197 app.kubernetes.io/instance: sampleapp-dev
198- app.k8s.io/component: sampleappdev
198+ app.k8s.io/component: sampleapp-dev
199+ type: NodePort
199200` ` `
200201
201202# # Resources
0 commit comments