GitHub -> Local -> Docker Hub -> GitHub -> Docker Hub -> k8s
- Windows 10
- WSL2 + Docker for Windows
- VSCode
- GitHub account
- Docker Hub account
- Make a new repository
- e.g.,
sample-svc
- e.g.,
- Start WSL
- Clone the github repository
- Open the repo folder from WSL with
code sample-svc
command
The editor opens the repo folder within WSL.
- Make index.html
- Make Dockerfile
- Open terminal in VSCode
- Build a container
docker build -t username/sample-svc
- Test a container
- Build a container
$ docker run -d -it --name svc username/sample-svc
$ docker exec svc /bin/sh -c "curl -s localhost"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Service</title>
</head>
<body>
<h1>Sample Service</h1>
</body>
</html>
- Push to Docker Hub
$ docker push username/sample-svc
- Commit to GitHub
$ git add .
$ git commit -m "Initial commit"
$ git push origin master
- Go to the image build page
- Select GitHub from Automated Builds
- Select
Connect
to GitHub from Linked Accounts- Give an authentication
- Come back to the image build page again
- Select GitHub (Connected) from Automated Builds
- Select your account and repository (
sample-svc
) -> Save
- Change the title of index.html to
Sample Microservice
- Commit the change
$ git add .
$ git commit -m "Changed the title"
$ git push origin master
- Check if the image is registered in the queue from the image build page
- Wait until the image is successfully built
- Make sample-svc.yaml
$ kubectl apply -f sample-svc.yaml
namespace/sample-svc unchanged
deployment.apps/sample-svc unchanged
service/sample-svc configured
$ kubectl get svc -A # Determine the internal port to which 80 is mapped
$ curl -s a-k8s-node:port
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Microservice</title>
</head>
<body>
<h1>Sample Service</h1>
</body>
</html>
- Change the body text to
Sample Microservice
- Commit the change
- Wait until the new image is successfully built
- Reload the image
$ kubectl rollout restart deployment sample-svc -n sample-svc
deployment.apps/sample-svc restarted
$ kubectl get svc -A # Same drill
$ curl -s a-k8s-node:port
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sample Microservice</title>
</head>
<body>
<h1>Sample Microservice</h1>
</body>
</html>
- Delete the whole thing
$ delete ns sample-svc