Cloud Docker Google Gloud

3 Bước tạo docker image Google Kubernetes Engine

Google Kubernetes Engine

phần 1 chúng ta đã tạo xong cluster Kubernetes, trong phần 2 này chúng ta sẽ tạo một docker image, sau đó push lên Container Registry của Google. Đây là một dịch vụ lưu trữ images giống docker hub.

Google Kubernetes Engine

1.Tạo webserver từ Cloud Shell

Đầu tiên, truy cập vào GCP Console : https://console.cloud.google.com/home/ , để mở Cloud Shell. và thực thi các câu lệnh sau để tiến hành khởi tạo server:

congdonglinux.com-quan-ly-ha-tang-cloud-with-terraform-5

mkdir helloNode
cd helloNode

Tải file server.js về :  

wget https://raw.githubusercontent.com/GoogleCloudPlatform/gcp-getting-started-lab-jp/master/fundamental/gke/helloNode/server.js
  • server.js sẽ tạo ra một webservice đơn giản, in ra dòng chữ “Hello World! == ” + hostname” và listening trên port 8080.
  • Thực thi file server.js bằng câu lệnh để chạy thử dịch vụ: node server.js
  • Chọn preview port 8080 chúng ta sẽ có kết quả hiển thị giống hình dưới.

docker image Google Kubernetes Engine

Screenshot 2020 07 09 17.12.13

Quay lại màn hình terminal, dùng Ctrl+C để tắt server node đang chạy.

2. Tạo image và push lên Container Registry

Trong màn hình Cloud Shell,  chạy lệnh sau để thiết lập project ID:

gcloud config set project <ProjectID>   export PROJECT_ID=<ProjectID>
docker image Google Kubernetes Engine2

Chạy những lệnh sau để lấy Dockerfile và build images docker : 

wget https://raw.githubusercontent.com/GoogleCloudPlatform/gcp-getting-started-lab-jp/master/fundamental/gke/helloNode/Dockerfile

asia.gcr.io/${PROJECT_ID}/hello-node:v1     .

docker push asia.gcr.io/${PROJECT_ID}/hello-node:v1

Khi đó tại màn hình GCP console, menu bên trái Container Registry sẽ hiển thị images mà chúng ta vừa push lên: hello-node

docker image Google Kubernetes Engine 1

3.Triển khai images từ Container registry

Ở Cloud Shell Terminal chúng ta chạy lệnh sau:

docker run -itd -p 8080:8080 asia.gcr.io/${PROJECT_ID}/hello-node:v1
Như vậy là xong, chúng ta tiến hành truy cập Web preview để xem thành quả.
docker image Google Kubernetes Engine
Screenshot 2020 07 10 09.46.59

Kết bài

Vậy chúng ta kết thúc phần 2 ở đây. Chúng ta đã tìm hiểu qua cách để tạo , build và push images lên container registry của google. Trong phần 3, chúng ta sẽ tìm hiểu về cách để Deploy lên Google Kubernetes Engine. Cám ơn bạn đã quan tâm, chúc thành công !

Google Kubernetes Engine Series:

        Nguồn:                  

congdonglinux.com

              [maxbutton id=”2″ ]                             [maxbutton id=”3″ ] 

 

 

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !