Last active
March 9, 2021 21:12
-
-
Save ryanj/f29fa6d56c2c1dc667a2756349cfa776 to your computer and use it in GitHub Desktop.
Local Development with minikube http://bit.ly/k8s-minidev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section data-transition='concave'> | |
<section id='local-development-with-minikube'> | |
<a href="https://github.com/kubernetes/minikube"><img style="width:30%;" src="https://raw.githubusercontent.com/kubernetes/minikube/master/logo/logo.png" /></a> | |
<h2>Local Development</h2> | |
<p>with</p> | |
<h1><a href="https://github.com/kubernetes/minikube"><code>minikube</code></a></h1> | |
<br/> | |
<h4 class='fragment grow'><a href="http://bit.ly/k8s-minikube"><code>bit.ly/k8s-minidev</code></a></h4> | |
</section> | |
<section data-background-transition='fade' data-background='black' id='presented-by-ryanj'> | |
<p>presented by <a href="http://twitter.com/ryanj/">@ryanj</a>, Developer Advocate at <a href='http://redhat.com' style='color:red;'>Red Hat</a></p> | |
<p><a href="http://twitter.com/ryanj/"><img alt="ryanj" src="http://ryanjarvinen.com/images/ryanj-mestrefungo-com.gif" style="width:50%" /></p> | |
</section> | |
</section> | |
<section data-transition='concave' id='overview' data-markdown> | |
## 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) | |
</section> | |
<section id='git'> | |
<h3>Install git</h3> | |
<p>Install <code>git</code> using the instructions here:</p> | |
<p><a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">https://git-scm.com/book/en/v2/Getting-Started-Installing-Git</a></p> | |
<p>To verify <code>git</code> availability, run:</p> | |
<pre><code contenteditable>git version</code></pre> | |
</section> | |
<section data-transition='zoom-in convex-out' id='ready'> | |
<h1><i>Ready?</i></h1> | |
<br/> | |
<div class='fragment fade-up'> | |
<p>Verify that your local Kubernetes environment is ready by running:<br/> | |
<pre><code contenteditable>kubectl version</code></pre> | |
<p>The output should include your <code>kubectl</code> version info, and the release version of the kubernetes API server (when accessible)</p> | |
</div> | |
</section> | |
</section> | |
<section data-transition="zoom"> | |
<section data-transition="zoom" data-markdown> | |
# Let's Go! | |
</section> | |
</section> | |
<section data-transition="zoom"> | |
<section data-transition="zoom" data-markdown> | |
# Local Dev | |
## with `minikube` | |
</section> | |
<section id='needs'> | |
<p>Kubernetes provides portable abstractions for working with distributed solitions:</p> | |
<ol> | |
<li class='fragment'>standardized packaging (containers, volumes, pods)</li> | |
<li class='fragment'>load balancing (services)</li> | |
<li class='fragment'>scaling automation (replica sets)</li> | |
</ol> | |
<br/> | |
<br/> | |
<h5 class='fragment' id="need-any-of-these-for-local-development-">Need any of these for local development?</h5> | |
</section> | |
<section id='why-local'> | |
<h3 id="why-run-k8s-locally-">Why run K8s locally?</h3> | |
<p>As web development is increasingly being carried out using container-based microservices:</p> | |
<ol> | |
<li class='fragment'>ability to offer reproducible development environments | |
<ul><li class='fragment'>reduce onboarding time for new devs</li></ul></li> | |
<li class='fragment'>minimize deltas between dev and prod environments | |
<ul><li class='fragment'>fewer surprises when promoting code leads to faster velocity</li></ul></li> | |
<li class='fragment'>decentralize your release pipeline, allow CI test suites to be run locally | |
<ul><li class='fragment'>provide functional / systems-integration feedback earlier in the dev lifecycle</li></ul></li> | |
<li class='fragment'>potenial for fully offline development | |
<ul><li class='fragment'><expanding brain meme></li></ul></li> | |
</ol> | |
</section> | |
</section> | |
<section> | |
<section id='checklist' data-markdown> | |
### 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 | |
</section> | |
</section> | |
<section> | |
<section data-background-transition='zoom' id='onboarding' data-markdown> | |
## Onboarding | |
</section> | |
<section> | |
<h3>Onboarding - Yesterday's Jam</h3> | |
<ol> | |
<li class='fragment'><code>git clone https://github.com/ryanj/metrics-k8s</code></li> | |
<li class='fragment'><code>cd metrics-k8s</code></li> | |
<li class='fragment'><code><span style="text-decoration: line-through;">npm install</span></code></li> | |
<li class='fragment'><code><span style="text-decoration: line-through;">npm start</span></code></li> | |
</ol> | |
</section> | |
<section data-markdown> | |
### 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 | |
``` | |
</section> | |
<section data-markdown> | |
### 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 | |
``` | |
</section> | |
</section> | |
<section> | |
<section id='preview' data-markdown> | |
## Preview Changes | |
</section> | |
<section data-markdown> | |
## Preview - local files | |
First, share your local clone of `metrics-k8s` with minikube: | |
```bash | |
minikube mount $(pwd):/var/www/html | |
``` | |
</section> | |
<section data-markdown> | |
## 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: {} | |
``` | |
</section> | |
<section data-markdown> | |
### 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 | |
``` | |
</section> | |
<section data-markdown> | |
### 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 | |
</section> | |
</section> | |
<section> | |
<section data-background-transition='zoom' id='test' data-markdown> | |
## Test | |
</section> | |
<section id="test-rollout"> | |
<h3>Test - Rollout</h3> | |
<ol> | |
<li>Verify that <a href="#/docker">your <code>docker-env</code> is configured for minikube</a></li> | |
<li>Run a build | |
<pre><code>docker build . -t yourname/metrics-k8s:v1</code></pre></li> | |
<li>Update <code>metrics-review.yaml</code>, setting the container <code>image</code> to: | |
<pre><code>yourname/metrics-k8s:v1</code></pre></li> | |
<li>Apply the changes locally: | |
<pre><code>kubectl apply -f metrics-review.yaml</code></pre></li> | |
<li>Check your latest before promoting: | |
<pre><code>minikube service metrics-review</code></pre></li> | |
</ol> | |
</section> | |
</section> | |
<section> | |
<section data-transition='zoom' id='promote' data-markdown> | |
## Promote Changes | |
</section> | |
<section data-markdown> | |
### Promoting Changes | |
1. `git push`? | |
2. send PR? | |
3. next steps TBD / handled by CI suite | |
</section> | |
</section> | |
<section data-transition='concave' id='next-steps'> | |
<h3>Congratulations on completing:</h3> | |
<p> | |
<a href="http://bit.ly/k8s-minidev"> | |
<b>Local Development with <code>minikube</code></b> | |
<h5 class='fragment grow'><code>bit.ly/k8s-minidev</code></h5> | |
</a> | |
</p> | |
<br/> | |
<h4><i>Next Steps</i></h4> | |
<p>Continue learning with other <a href="http://bit.ly/k8s-workshops"><code>k8s-workshops</code></a>:</p> | |
<ol> | |
<li><a href="http://bit.ly/k8s-miniarch"><b>Kubernetes Architecture (adapted for <code>minikube</code>)</b><br/>bit.ly/k8s-miniarch</a></li> | |
</ol> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment