-
Create new Github Personal Access Token with read:packages scope at https://github.com/settings/tokens/new
-
Base-64 encode :
$ echo -n <github-username>:<TOKEN> | base64 <AUTH>
-
Manually create the secret:
$ echo '{"auths":{"docker.pkg.github.com":{"auth":"<AUTH>"}}}' | kubectl create secret generic dockerconfigjson-github-com --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=/dev/stdin
-
Now, you can reference the above secret from your pod's spec definition via imagePullSecrets field:
spec: containers: - name: your-container-name image: docker.pkg.github.com/<ORG>/<REPO>/<PKG>:<TAG> imagePullSecrets: - name: dockerconfigjson-github-com
Skaffold watches for file changes and rebuilds thereby allowing for quicker local development.
# start minikube
$ minikube start
# switch to using an existing namespace
$ kubectl config set-context --current --namespace <NAMESPACE>
$ skaffold dev --port-forward
Port forwarding service/helloworld-api-load-balancer in namespace devsam, remote port 8080 -> address 127.0.0.1 port 8080
# In a separate terminal, test the endpoint (below example uses HTTPie)
$ http localhost:8080
HTTP/1.1 200 OK
Content-Length: 39
Content-Type: application/json
Date: Fri, 11 Dec 2020 12:12:45 GMT
{
"Message": "Hello, World",
"Status": 200
}
Instructions for running on macOS using minikube
# start minikube
$ minkube start
# switch to using a namespace
$ kubectl config set-context --current --namespace <NAMESPACE>
# apply Kubernetes config
$ kubectl apply -f k8s
# Start minikube tunnel service
$ minikube service helloworld-api-load-balancer -n <NAMESPACE>
# outputs something like:
|-----------|------------------------------|-------------|-------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------------------------|-------------|-------------------------|
| devsam | helloworld-api-load-balancer | 8080 | http://172.17.0.2:32464 |
|-----------|------------------------------|-------------|-------------------------|
🏃 Starting tunnel for service helloworld-api-load-balancer.
|-----------|------------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------------------------|-------------|------------------------|
| devsam | helloworld-api-load-balancer | | http://127.0.0.1:62282 |
|-----------|------------------------------|-------------|------------------------|
🎉 Opening service devsam/helloworld-api-load-balancer in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
# To also test on the command line
$ http http://127.0.0.1:62282
# build
$ docker build -t helloworldapi .
# run using local image
$ docker run -p 8080:8080 -it helloworldapi
Merges to the main branch will trigger the CI action to test the code and if the tests are green to publish a "latest" image.
In order to tag an image, add a git tag against the main branch and push. This will trigger CI and publish the versioned image.
# add a tag
git tag <tag e.g. v0.3.0> -am <tag>
# push the tag to remote which will trigger CI
git push --follow-tags
go test -v -cover