반응형

Tasks

An application image with a v1 tag has been pushed to the gcr.io repository
A new Kubernetes cluster exists (zone: us-central1-a)
Check that an application has been deployed to the cluster
Test that a service exists that responds to requests like Echo-app

 

1. 클러스터 생성


gcloud beta container --project "qwiklabs-gcp-00-337f72711928" clusters create "echo-cluster" --zone "us-central1-a" --no-enable-basic-auth --cluster-version "1.14.10-gke.17" --machine-type "n1-standard-2" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "
https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --enable-stackdriver-kubernetes --enable-ip-alias --network "projects/qwiklabs-gcp-00-337f72711928/global/networks/default" --subnetwork "projects/qwiklabs-gcp-00-337f72711928/regions/us-central1/subnetworks/default" --default-max-pods-per-node "110" --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair

 

클러스터 생성은 Cloud Console 에서 직접 하면 된다.

name 은 "echo-cluster" , machine-type 은 "n1-standard-2" 로 만들어 준다.

 

2. tar file 을 Google Cloud Storage 에서 복사한 후 압축을 푼다.

 

- Google Cloud Strage 에서 복사

gsutil cp gs://qwiklabs-gcp-00-337f72711928/echo-web.tar.gz .

- 압축 풀기
tar -xvfz echo-web.tar

 

 

3. Docker Build 및 Image Push

- Docker Build

- Image 확인

echo-app 이 생성된 것을 확인할 수 있다.

 

- GCR(Google Cloud Registry) 에 push 하기 위해서 Tag 를 변경해준다. 

export PROJECT_ID=$(gcloud info --format='value(config.project)')

docker tag echo-app:v1 gcr.io/${PROJECT_ID}/echo-app:v1

- Image 를 Cloud Registry 에 push

중간에 나는 project id 를 그대로 써줬는데 위에서 export 를 했기 때문에 ${PROEJCT_ID} 로 써줘도 된다.

 

4. GKE 에 Deploy 하기

Cloud Console  의 Container Registry 를 확인해 보면 위와 같이 push한 이미지를 확인 할 수 있다.

오른쪽에 ... 메뉴를 눌러보면 Deploy to GKE 버튼을 볼수 있다. 그걸 클릭한다. 

 

Image 는 "Exsiting conatiner images" 를 선택하고 좀전에 생성한 이미지를 선택해준다.

 

Application name 은 "echo-web" 이라고 해준다.

라벨에도 key에 app, value 에 echo-web 이라고 넣어준다.

Cluster 는 위에서 생성한 "echo-cluster" 를 선택한다.

그리고 "Deploy" 클릭.

 

5. 외부에서 접속 할수 있도록 expose 하기

 

Cloud Console 에서 Kubernetes Engine > Workloads 메뉴로 가면 echo-web 의 detail 정보로 들어가면 위와 같이 화면이 나온다.

화면 상단에 있는 Expose 버튼을 누른다.

 

port 를 80 으로 넣어주고 Target port 를 8080 으로 넣고 Expose 버튼을 누른다.

 

Expose 가 완료되면 위와같이 External endpoint 가 나타난다.

 

주소로 접속을 하게 되면 위와 같이 결과를 볼 수 잇다.

Cloud console 메뉴를 이용해서 만들었는데 직접 kubectl 명령어를 활용해서 만들어 보는것도 좋은 공부가 될것 같다.

 

 

 

 

728x90
반응형
반응형

 먼저 Dockerfile 이 있다고 가정한다. 

내가 만든 이미지는 spring boot 어플리케이션이다.


Dockerfile


1
2
3
4
5
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY ./build/libs/mail-0.0.1-SNAPSHOT.jar app.jar
RUN echo 'Mail Service running'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
cs


이제 이 Dockerfile 을 빌드를 한다.


sudo docker build -t asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1 .


docker build : 컨테이너를 만드는 명령어

-t : 이미지에 태그 정하는 옵션

asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1 : 후에 구글 컨테이너 레지스트리에 올리기 위한 이름 규칙이다.


[HOST_NAME]/[GOOGE_PROJECT_ID]/[IMAGE_NAME]


# 참고 (출처 : https://cloud.google.com/container-registry/docs/pushing-and-pulling)

  • gcr.io hosts the images in the United States, but the location may change in the future
  • us.gcr.io hosts the image in the United States, in a separate storage bucket from images hosted by gcr.io
  • eu.gcr.io hosts the images in the European Union
  • asia.gcr.io hosts the images in Asia


1
2
3
4
5
sudo docker images
REPOSITORY                                        TAG                 IMAGE ID            CREATED             SIZE
asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service    v1                  2f19bede54dd        19 minutes ago      140MB
openjdk                                           8-jdk-alpine        54ae553cb104        5 weeks ago         103MB
hello-world                                       latest              4ab4c602aa5e        5 weeks ago         1.84kB
cs


이미지가 생성되면 위와 같이 볼수 있다. PROJECT_ID 는 일부러 [GOOGLE_PROJECT_ID] 라고 변경했다.

이제 이미지를 PUSH 해보자


1
2
3
4
5
6
7
8
sudo docker push asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1
The push refers to repository [asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service]
fcb96fbc948c: Preparing 
f2ec1bba02a6: Preparing 
0c3170905795: Preparing 
df64d3292fd6: Preparing 
unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.
com/container-registry/docs/advanced-authentication
cs


안된다...

뭔가 인증작업이 필요하다.

저기 표시된 url  로 일단 들어가보자. https://cloud.google.com/container-registry/docs/advanced-authentication


거기 가이드 대로 따라해보면 다음과 같은 과정을 거치게 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
gcloud auth configure-docker
WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.
The following settings will be added to your Docker config file 
located at [/home/gcpblusky0910/.docker/config.json]:
 {
  "credHelpers": {
    "gcr.io": "gcloud", 
    "us.gcr.io": "gcloud", 
    "eu.gcr.io": "gcloud", 
    "asia.gcr.io": "gcloud", 
    "staging-k8s.gcr.io": "gcloud", 
    "marketplace.gcr.io": "gcloud"
  }
}
 
Do you want to continue (Y/n)?  y
 
Docker configuration file updated.
cs


그런데 위에 내용이 뭔가 좀 이상하다. 

config 파일에 내용이 들어가긴 했는데 다음과 같은 문구가 눈에 거슬린다.


WARNING: `docker-credential-gcloud` not in system PATH.
gcloud's Docker credential helper can be configured but it will not work until this is corrected.


'docker-credential-gcloud' 가 PATH에 없어서 Docker credential helper 를 설정했지만 정상적으로 동작 안할꺼다.. 라는 내용이다. 뭐지???


1
gcloud components install docker-credential-gcr
cs


이렇게 했더니 다시 에러가 난다. 이번에는 Cloud SDK 가 뭔가 없다고 한다. 


그래서 아래 URL 로 이동해서 Cloud SDK 를 설치했다.


https://cloud.google.com/sdk/docs/downloads-apt-get


거기에 있는 명령어들을 쭉 실행 한다음 마지막에 gcloud init 까지 한다.


1
2
gcloud auth configure-docker
gcloud credential helpers already registered correctly.
cs
gcloud components install docker-credential-gcr


이제서야 Error 없이 뭔가 OK 라고 나온다.


이제 다시 이미지는 컨테이너 레지스트리에 push를 해보자.


1
2
3
4
5
6
7
sudo docker push asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service:v1
The push refers to repository [asia.gcr.io/[GOOGLE_PROJECT_ID]/mail-service]
fcb96fbc948c: Pushed 
f2ec1bba02a6: Layer already exists 
0c3170905795: Layer already exists 
df64d3292fd6: Layer already exists 
v1: digest: sha256:465521bc0b83e3a3177c25f1f120f96bef3d585046f0b4cb4ede4d42d1fafc7a size: 1159
cs



이렇게 내 계정의 Container Registry 를 확인해보면 정상적으로 업로드가 됐다.


728x90
반응형

'Development > GoogleCloud' 카테고리의 다른 글

[GCP] Google Cloud Storage Options.  (0) 2019.12.12
[GCP]VPC Network  (0) 2019.08.03
[GCP] Network  (0) 2019.08.01
[GCP]HTTP(S) Load Balancing  (0) 2019.07.31
[GCP]Network TCP/UDP Load Balancing  (0) 2019.07.28
반응형

Docker 도큐먼트를 따라하다 보니 갑자기 에러가 난다. 분명 난 똑같이 붙여넣기 하고 그대로 한것 같은데..


https://docs.docker.com/get-started/part2/#build-the-app


unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/ubuntu/study_docker/Dockerfile: no such file or directory


대체 왜나는 거지??? 분명 해석을 해보면 Dockerfile 이 저 위치에 없다는 이야기 인데...

있는데 분명히.... 뭐~~~가 잘못된거지???


헉!!! DockerFile........ 파일 이름이 Dockerfile 이 아닌 DockerFile 로 해놨다..

그래서 변경했더니 잘만 된다...


docker build

Estimated reading time: 21 minutes

Description

Build an image from a Dockerfile

(출처 : https://docs.docker.com/engine/reference/commandline/build/)


딱 저기에도 Dockerfile을 build한다고 써있다.



728x90
반응형

+ Recent posts