@@ -177,6 +177,96 @@ kubectl --namespace default port-forward service/compare-helm 8888:80
177177
178178Then, you are able to access your site through ` http://localhost:8888/ ` .
179179
180+ ## Deploy to multiple environments
181+
182+ ### Docker images
183+
184+ Create two docker images first, one for ` nas ` , another for ` prod ` .
185+
186+ ``` sh
187+ docker build -t jojozhuang/text-compare-angular-nas -f Dockerfile-nas .
188+ docker build -t jojozhuang/text-compare-angular-prod -f Dockerfile-prod .
189+ ```
190+
191+ List all images and make sure ` jojozhuang/text-compare-angular-nas ` and ` jojozhuang/text-compare-angular-prod ` are there.
192+
193+ ``` sh
194+ docker images
195+ REPOSITORY TAG IMAGE ID CREATED SIZE
196+ jojozhuang/text-compare-angular-prod latest 4a53306114f5 4 seconds ago 30.8MB
197+ jojozhuang/text-compare-angular-nas latest ee561a5e50b3 5 hours ago 30.8MB
198+ jojozhuang/text-compare-angular latest ee561a5e50b3 5 hours ago 30.8MB
199+ ```
200+
201+ Push to docker hub.
202+
203+ ``` sh
204+ docker push jojozhuang/text-compare-angular-nas
205+ docker push jojozhuang/text-compare-angular-prod
206+ ```
207+
208+ If you don't push them to hub.docker.com, you might get ` ErrImagePull ` error.
209+
210+ ``` sh
211+ kubectl get all -n prod
212+ NAME READY STATUS RESTARTS AGE
213+ pod/compare-helm-57f779585d-6c665 0/1 ErrImageNeverPull 0 5s
214+ pod/compare-helm-6c5668997f-kzk9n 0/1 ErrImagePull 0 105s
215+ ```
216+
217+ ### Environment specified value files
218+
219+ Copy ` values.yaml ` and create for ` nas ` and ` prod ` env.
220+
221+ ``` sh
222+ kubectl create namespace nas
223+ kubectl create namespace prod
224+ ```
225+
226+ Check new namespaces ` nas ` and ` prod ` are created.
227+
228+ ``` sh
229+ kubectl get namespaces
230+ NAME STATUS AGE
231+ bit-developer Active 70m
232+ default Active 6h24m
233+ kube-node-lease Active 6h24m
234+ kube-public Active 6h24m
235+ kube-system Active 6h24m
236+ kubernetes-dashboard Active 6h23m
237+ nas Active 14s
238+ prod Active 13s
239+ ```
240+
241+ Install for nas and prod namespaces.
242+
243+ ``` sh
244+ helm install compare-helm-nas deployment --values deployment/values.yaml -f deployment/values-nas.yaml -n nas
245+ helm install compare-helm-prod deployment --values deployment/values.yaml -f deployment/values-prod.yaml -n prod
246+ ```
247+
248+ List all namespaces.
249+
250+ ``` sh
251+ helm ls --all-namespaces
252+ NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
253+ compare-helm default 6 2024-01-07 21:49:34.420836 -0800 PST deployed deployment-0.1.0 1.16.0
254+ compare-helm-nas nas 1 2024-01-07 22:10:09.473106 -0800 PST deployed deployment-0.1.0 1.16.0
255+ compare-helm-prod prod 1 2024-01-07 22:10:20.00086 -0800 PST deployed deployment-0.1.0 1.16.0
256+ ```
257+
258+ ``` sh
259+ kubectl get all -n prod
260+ kubectl describe pod compare-helm-77ddc9bc6b-xf96c -n prod
261+ ```
262+
263+ ``` sh
264+ helm upgrade compare-helm-nas deployment --values deployment/values.yaml -f deployment/values-nas.yaml -n nas
265+ helm upgrade compare-helm-prod deployment --values deployment/values.yaml -f deployment/values-prod.yaml -n prod
266+ ```
267+
268+ Start nas service and prod service seperately and access ` http://localhost:8888/ ` . You will see the env name on the home page is shown correctly, from ` nas ` to ` production ` .
269+
180270- [ How to Create Helm Charts - The Ultimate Guide] ( https://www.youtube.com/watch?v=jUYNS90nq8U&ab_channel=DevOpsJourney )
181271
182272# Deployment
0 commit comments