Local Development

with

minikube


bit.ly/k8s-minidev

presented by @ryanj, Developer Advocate at Red Hat

ryanj

## Local Access to Kubernetes To follow along, [complete the `k8s-minikube` workshop module to install `minikube`, `kubectl`, and `docker`, locally on your system](http://bit.ly/k8s-minikube)

Install git

Install git using the instructions here:

https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

To verify git availability, run:

git version

Ready?


Verify that your local Kubernetes environment is ready by running:

kubectl version

The output should include your kubectl version info, and the release version of the kubernetes API server (when accessible)

# Let's Go!
# Local Dev ## with `minikube`

Kubernetes provides portable abstractions for working with distributed solitions:

  1. standardized packaging (containers, volumes, pods)
  2. load balancing (services)
  3. scaling automation (replica sets)


Need any of these for local development?

Why run K8s locally?

As web development is increasingly being carried out using container-based microservices:

  1. ability to offer reproducible development environments
    • reduce onboarding time for new devs
  2. minimize deltas between dev and prod environments
    • fewer surprises when promoting code leads to faster velocity
  3. decentralize your release pipeline, allow CI test suites to be run locally
    • provide functional / systems-integration feedback earlier in the dev lifecycle
  4. potenial for fully offline development
    • <expanding brain meme>
### Local Development Checklist: 1. [onboarding](#/onboarding) - show someone new how to run the `:latest` release 2. [preview changes](#/preview) - review changes and iterate on a solution 3. [test changes](#/test) - build and deploy 4. [promote changes](#/promote) - git push
## Onboarding

Onboarding - Yesterday's Jam

  1. git clone https://github.com/ryanj/metrics-k8s
  2. cd metrics-k8s
  3. npm install
  4. npm start
### Onboarding - Add K8s Generate kubernetes `deployment` and `service` specifications, both named `metrics-review`: ```bash kubectl run metrics-review --image=quay.io/ryanj/metrics-k8s \ --expose --port=2015 --service-overrides='{ "spec": { "type": "NodePort" } }' \ --dry-run -o yaml > metrics-review.yaml ```
### Onboarding - deploy :latest Test your generated spec: ```bash kubectl create -f metrics-review.yaml ``` Minikube users will be able to open the resulting service in their browser by running: ```bash minikube service metrics-review ```
## Preview Changes
## Preview - local files First, share your local clone of `metrics-k8s` with minikube: ```bash minikube mount $(pwd):/var/www/html ```
## Preview - hostPath Next, produce a new deployment spec that includes (minimal) support for live development workflows: 1. `cp metrics-review.yaml metrics-dev.yaml` 2. replace `metrics-review` with `metrics-dev` (global) 2. Add a `hostPort` volume to access your local repo: ```diff spec: containers: - image: quay.io/ryanj/metrics-k8s name: metrics-dev ports: - containerPort: 2015 resources: {} + volumeMounts: + - mountPath: /var/www/html + name: metrics-src + volumes: + - name: metrics-src + hostPath: + path: /var/www/html status: {} ```
### Preview The resulting file should look just like the included [metrics-dev.yaml](https://raw.githubusercontent.com/ryanj/metrics-k8s/master/metrics-dev.yaml) file from the `metrics-k8s` git repo. Try launching it with: ```bash kubectl create -f metrics-dev.yaml ```
### Preview Verify that any changes written to your local repo become immediately visible when reloading your browser window: 1. view your latest ```bash minikube service metrics-dev ``` 2. make a change to `index.html` 3. reload your browser
## Test

Test - Rollout

  1. Verify that your docker-env is configured for minikube
  2. Run a build
    docker build . -t yourname/metrics-k8s:v1
  3. Update metrics-review.yaml, setting the container image to:
    yourname/metrics-k8s:v1
  4. Apply the changes locally:
    kubectl apply -f metrics-review.yaml
  5. Check your latest before promoting:
    minikube service metrics-review
## Promote Changes
### Promoting Changes 1. `git push`? 2. send PR? 3. next steps TBD / handled by CI suite

Congratulations on completing:

Local Development with minikube

bit.ly/k8s-minidev


Next Steps

Continue learning with other k8s-workshops:

  1. Kubernetes Architecture (adapted for minikube)
    bit.ly/k8s-miniarch
Presented by: @ryanj