GSP-318: Deploy to Kubernetes in Google Cloud
컨텐츠 정보
- 3,256 조회
- 8 댓글
- 0 추천
- 목록
본문
https://www.youtube.com/watch?v=KyaGr7atDko
## Task - 1 : Create a Docker image and store the Dockerfile
```
gcloud auth list
gsutil cat gs://cloud-training/gsp318/marking/setup_marking_v2.sh | bash
gcloud source repos clone valkyrie-app
cd valkyrie-app
cat > Dockerfile "<<"EOF
FROM golang:1.10
WORKDIR /go/src/app
COPY source .
RUN go install -v
ENTRYPOINT ["app","-single=true","-port=8080"]
EOF
docker build -t : .
cd ..
cd marking
./step1_v2.sh
```
## Task - 2 : Test the created Docker image
```
cd ..
cd valkyrie-app
docker run -p 8080:8080 : &
cd ..
cd marking
./step2_v2.sh
```
## Task - 3 : Push the Docker image in the Google Container Repository
```
cd ..
cd valkyrie-app
docker tag : gcr.io/$GOOGLE_CLOUD_PROJECT/:
docker push gcr.io/$GOOGLE_CLOUD_PROJECT/:
```
## Task - 4 : Create and expose a deployment in Kubernetes
```
sed -i s#IMAGE_HERE#gcr.io/$GOOGLE_CLOUD_PROJECT/:#g k8s/deployment.yaml
gcloud container clusters get-credentials valkyrie-dev --zone us-east1-d
kubectl create -f k8s/deployment.yaml
kubectl create -f k8s/service.yaml
```
## Task - 5 : Update the deployment with a new version of valkyrie-app
```
git merge origin/kurt-dev
kubectl edit deployment valkyrie-dev
### change replicas from 1 to
### change to in two places
docker build -t gcr.io/$GOOGLE_CLOUD_PROJECT/: .
docker push gcr.io/$GOOGLE_CLOUD_PROJECT/:
```
## Task - 6 : Create a pipeline in Jenkins to deploy your app
```
docker ps
docker kill
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=cd" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
```
* **Open Jenkins Web View -> Preview on port 8080**
```
Username : admin
Password : {Code output from previous command}
```
```
Go through the following:
-> Manage Jenkins -> Manage Credentials -> Jenkins -> Global credentials (unrestricted) -> Add credentials -> Kind: Google Service Account from metadata -> OK
-> Jenkins -> New Item -> Name : valkyrie-app -> Pipeline -> Pipeline script from SCM -> Set SCM to git -> OK
-> Pipeline -> Script: Pipeline script from SCM -> SCM: Git
-> Repository URL: {find it using command: gcloud source repos list} -> Credentials: {Project id}
-> Apply -> Save
```
```
sed -i "s/green/orange/g" source/html.go
sed -i "s/YOUR_PROJECT/$GOOGLE_CLOUD_PROJECT/g" Jenkinsfile
git config --global user.email "[email protected]" // Email
git config --global user.name "student..." // Username
git add .
git commit -m "built pipeline init"
git push
```
관련자료
-
링크
댓글 8
/ 1 페이지
SDK님의 댓글
clone
Task 2
gcloud source repos clone valkyrie-app
cat > Dockerfile <<EOF
FROM golang:1.10
WORKDIR /go/src/app
COPY source .
RUN go install -v
ENTRYPOINT ["app","-single=true","-port=8080"]
EOF
Task 2
cd ..
cd valkyrie-app
docker run -p 8080:8080 <Docker Image>:<Tag Name> &
cd ..
cd marking
./step2_v2.sh
SDK님의 댓글
Task - 4 : Create and expose a deployment in Kubernetes
sed -i s#IMAGE_HERE#gcr.io/$GOOGLE_CLOUD_PROJECT/<Docker Image>:<Tag Name>#g k8s/deployment.yaml
gcloud container clusters get-credentials valkyrie-dev --zone us-east1-d
kubectl create -f k8s/deployment.yaml
kubectl create -f k8s/service.yaml
SDK님의 댓글
Task - 5 : Update the deployment with a new version of valkyrie-app
git merge origin/kurt-dev
kubectl edit deployment valkyrie-dev
### change replicas from 1 to <Replicas Count>
### change <Tag Name> to <Updated Version> in two places
docker build -t gcr.io/$GOOGLE_CLOUD_PROJECT/<Docker Image>:<Updated Version> .
docker push gcr.io/$GOOGLE_CLOUD_PROJECT/<Docker Image>:<Updated Version>
SDK님의 댓글
Task - 6 : Create a pipeline in Jenkins to deploy your app
docker ps
docker kill <take container_id from above command>
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=cd" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
SDK님의 댓글
Open Jenkins Web View -> Preview on port 8080
Go through the following:
-> Manage Jenkins -> Manage Credentials -> Jenkins -> Global credentials (unrestricted) -> Add credentials -> Kind: Google Service Account from metadata -> OK
-> Jenkins -> New Item -> Name : valkyrie-app -> Pipeline -> Pipeline script from SCM -> Set SCM to git -> OK
-> Pipeline -> Script: Pipeline script from SCM -> SCM: Git
-> Repository URL: {find it using command: gcloud source repos list} -> Credentials: {Project id}
-> Apply -> Save
Go through the following:
-> Manage Jenkins -> Manage Credentials -> Jenkins -> Global credentials (unrestricted) -> Add credentials -> Kind: Google Service Account from metadata -> OK
-> Jenkins -> New Item -> Name : valkyrie-app -> Pipeline -> Pipeline script from SCM -> Set SCM to git -> OK
-> Pipeline -> Script: Pipeline script from SCM -> SCM: Git
-> Repository URL: {find it using command: gcloud source repos list} -> Credentials: {Project id}
-> Apply -> Save
SDK님의 댓글
sed -i "s/green/orange/g" source/html.go
sed -i "s/YOUR_PROJECT/$GOOGLE_CLOUD_PROJECT/g" Jenkinsfile
git config --global user.email "[email protected]" // Email
git config --global user.name "student..." // Username
git add .
git commit -m "built pipeline init"
git push