You are browsing a read-only backup copy of Wikitech. The primary site can be found at wikitech.wikimedia.org
User:Jeena Huneidi/Kubernetes Migration
Migrating a service to Kubernetes
A Guide Using HelloWorldOid
- Create .pipeline/blubber.yaml
- Generate dockerfile using blubber
- Create docker image
- Create helm deployment chart
- Test in minikube (Try local-charts if you want to test integrations with other services/apps or do more development!)
- Create .pipeline/config.yaml
- Update integration/config to run the pipeline you created for testing and publishing your service
- Run benchmarks and update deployment chart
- Talk to SRE about deployment to production
We’re going to migrate HelloWorldOid to Kubernetes!
- Docker - https://www.docker.com/products/docker-desktop
- Minikube - https://kubernetes.io/docs/tasks/tools/install-minikube/ (you can try using the local-charts repo's installation script to install Minikube if you prefer)
Clone the Repositories:
- HelloWorldoid -
git clone ssh://gerrit.wikimedia.org:29418/blubber-doc/example/helloworldoid
- integration/config -
git clone ssh://gerrit.wikimedia.org:29418/integration/config
- deployment-charts -
git clone ssh://gerrit.wikimedia.org:29418/operations/deployment-charts
- local-charts (optional for testing integrations and developing) -
git clone ssh://gerrit.wikimedia.org:29418/releng/local-charts
Creating a Docker Image
Services running in production need a docker image generated and pushed to the wikimedia docker registry in CI. Notice the .pipeline/blubber.yaml file in the helloworldoid directory:
[image or code here]
blubber.yaml tells the blubber service what operating system, packages, libraries, and files are needed in your docker image. We need a docker image to deploy to Kubernetes because services in Kubernetes must be in a container. The blubber service will output a dockerfile that can be used to create your docker image. Some tutorials can be found here: []
1. Use the blubberoid service to create our dockerfile from the blubber configuration! Switch to the root directory of the helloworldoid repo.
curl -s "https://blubberoid.wikimedia.org/v1/production" \ -H 'content-type: application/yaml' \ --data-binary @".pipeline/blubber.yaml" > Dockerfile
3. Build the docker image:
docker build -t <imagetag> -f - .
4. Test the docker image:
docker run -d -p 8001:8001 hwoid curl localhost:8001
5. Clean up:
docker ps docker stop <container id> docker rm <container id>
Publishing Docker Images
It's great that our docker image runs, but we should take advantage of the continuous integration pipeline to build our images and publish them to a public repository so that others can use them too!
1. Switch over to the helloworldoid repo's .pipeline folder. Notice config.yaml
[image or code here]
config.yaml describes what actions need to happen in the continuous integration pipeline and what to publish, for example, tests and lint need to run before publishing a docker image. If you want to create your own pipeline configuration, some tutorials can be found here: []
2. Edit config.yaml:
3. Switch to the integration/config repo.
4. Edit jjb/project-pipelines.yaml:
Edit the helloworldoid project to include a publish pipeline
5. Edit zuul/layout.yaml:
Edit the helloworldoid project to have a publish pipeline
Congratulations! After these changes are merged, your images will be published to docker-registry.wikimedia.org! The images in the registry can be seen here: []
Our docker image has been built, but we still need a way to run it in Kubernetes.
Creating a Helm Chart
We use Helm charts to configure our Kubernetes deployments.
1. Switch to the deployment-charts repo.
2. Use the create_new_service.sh script to create our initial chart.
3. Edit the files created by the script with specific configuration for our service. Let's take a look:
Testing the Helm Chart
Let's test that our chart works using the local-charts environment. Add HelloWorldOid to local-charts:
1. In the local-charts repo, update requirements.yaml:
2. Add the configuration necessary for HelloWorldOid in values.yaml:
3. Try running HelloWorldOid in Kubernetes:
make deploy in the terminal to deploy to Minikube.
Whoops, I forgot to add something to our deployment chart. Let's change it now and run
make update to update our deployment.
Getting Deployed to Production
We have a deployment chart. What does it take to get our app deployed to production?
Now that we know our HelloWorldOid runs in Kubernetes, we can run benchmarks to determine how many resources it needs. This is required for deployment to production. Follow this tutorial to benchmark: https://wikitech.wikimedia.org/wiki/User:Alexandros_Kosiaris/Benchmarking_kubernetes_apps
Update the deployment-charts chart with the values discovered during the benchmark tests.