You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

User:Jeena Huneidi/Kubernetes Migration

From Wikitech-static
< User:Jeena Huneidi
Revision as of 17:25, 25 March 2020 by imported>Jeena Huneidi (Adjusting format)
Jump to navigation Jump to search

Migrating a service to Kubernetes

A Guide Using HelloWorldOid

TL;DR:

  1. Create .pipeline/blubber.yaml
  2. Generate dockerfile using blubber
  3. Create docker image
  4. Create helm deployment chart
  5. Test in minikube (Try local-charts if you want to test integrations with other services/apps or do more development!)
  6. Create .pipeline/config.yaml
  7. Update integration/config to run the pipeline you created for testing and publishing your service
  8. Run benchmarks and update deployment chart
  9. Talk to SRE about deployment to production

Set Up

We’re going to migrate HelloWorldOid to Kubernetes!

Pre-requirements:

Clone the Repositories:

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:

blubber.yaml:

[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]]

1. Use the blubberoid service to create our dockerfile from the blubber configuration!

       curl -s "https://blubberoid.wikimedia.org/v1/development" \                     
               -H 'content-type: application/yaml' \
               --data-binary @".pipeline/blubber.yaml" > Dockerfile

2. Create the docker image: eval $(minikube docker-env)

3. Build the docker image: docker build -t <imagetag> -f - .

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:

values.yaml

blah blah

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: Type 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.

Our deployment chart won't be usable by others until we have a published docker image, though.

Publishing Docker Images

It's great that we can now deploy to Kubernetes, 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

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]]

2. Edit config.yaml:

3. Switch to the integration/config repo.

4. Edit jjb/project-pipelines.yaml:

project-pipelines.yaml

Edit the helloworldoid project to include a publish pipeline

5. Edit zuul/layout.yaml:

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: [[3]]

Now we can edit our deployment chart to use the published version of the docker image and submit it for review. Don't forget to submit our changes to local-charts as well!

Getting Deployed to Production

We have a deployment chart. What does it take to get our app deployed to production?

Running Benchmarks

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.