Deploy to Kubernetes in Google Cloud: Challenge Lab

Solutions

Playlist

step 1: — — — — — — Create a Docker image and store the Dockerfile — — — — — — — — -

gsutil cat gs://cloud-training/gsp318/marking/setup_marking.sh | bashgcloud source repos clone valkyrie-appcd valkyrie-appcat > Dockerfile <<EOFFROM golang:1.10WORKDIR /go/src/appCOPY source .RUN go install -vENTRYPOINT ["app","-single=true","-port=8080"]EOFdocker build -t valkyrie-app:v0.0.1 .cd ..cd marking./step1.sh

step 2: — — — — — — Test the created Docker image — — — — — — — — -

cd ..cd valkyrie-appdocker run -p 8080:8080 valkyrie-app:v0.0.1 &cd ..cd marking./step2.sh

step 3: — — — — — — Push the Docker image in the Container Repository — — — — — — — — -

cd ..cd valkyrie-app
docker tag valkyrie-app:v0.0.1 gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.1
docker push gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.1
sed -i s#IMAGE_HERE#gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.1#g k8s/deployment.yaml

step 4: — — — — — — Create and expose a deployment in Kubernetes — — — — — — — — -

sed -i s#IMAGE_HERE#gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.1#g k8s/deployment.yamlgcloud container clusters get-credentials valkyrie-dev --zone us-east1-dkubectl create -f k8s/deployment.yamlkubectl create -f k8s/service.yamlgit merge origin/kurt-devkubectl edit deployment valkyrie-dev

step 5: — — — — — — Update the deployment with a new version of valkyrie-app — — — — — — — — -

docker build -t gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.2 . docker push gcr.io/$GOOGLE_CLOUD_PROJECT/valkyrie-app:v0.0.2kubectl edit deployment valkyrie-devdocker ps

step 6: — — — — — — — — — — Create a pipeline in Jenkins to deploy your app — — — — — — — — -

docker kill container_idexport 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);echogcloud source repos listsed -i "s/green/orange/g" source/html.go

Update project in Jenkinsfile

sed -i "s/YOUR_PROJECT/$GOOGLE_CLOUD_PROJECT/g" Jenkinsfilegit config --global user.email "you@example.com"     <------ put from first consol git config --global user.name "student"               <--------- from login statusgit add .git commit -m "built pipeline init"git push

in last on jenkins windows template just click on built which is in navigation menu.

--

--

--

Student | Content Creator | Explorer and Learner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Learn to code in less than a week

Account takeover in private program by simply guessing auth token (simple p1)

Appendix 1 Network Construction, Five Ways

9 Metrics for Balancing Speed and Accuracy in Product Development

SAS Programming: Zero My Hero — Using the Z Format with Numbers

The Liskov Substitution Principle — and why you might want to enforce it

Call for articles with rewards, spring bounty is Coming!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Astrodevil

Astrodevil

Student | Content Creator | Explorer and Learner

More from Medium

CI/CD pipeline with GitHub Actions

Real Clients, Real Users Phase at Encora Apprenticeship — Week 1

DevOps Girls 2021 in Review

Automating tests with Squash DEVOPS