-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from seifrajhi/kubernetes-local-development
feat add kubernetes local development
- Loading branch information
Showing
13 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"googlecloudtools.cloudcode", | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# Local Development with Kubernetes :wheel_of_dharma: | ||
|
||
Presentation of useful tools to develop with Kubernetes locally | ||
|
||
## Local cluster | ||
|
||
- [Minikube](https://github.com/kubernetes/minikube) : Run Kubernetes locally on Windows, Mac or Linux. | ||
- [demo](./minikube) | ||
|
||
- [MicroK8S](https://microk8s.io/) : A single package of k8s that installs on 42 flavours of Linux. | ||
|
||
- [Kind](https://kind.sigs.k8s.io/) : A tool for running local Kubernetes clusters using Docker container “nodes”. | ||
- [demo](./kind) | ||
|
||
- [kubeadm-dind-cluster](https://github.com/kubernetes-sigs/kubeadm-dind-cluster) : A Kubernetes multi-node test cluster based on kubeadm. *DEPRECATED* | ||
|
||
- [K3S](https://k3s.io/) / [K3D](https://k3d.io/) : lightweight Kubernetes distribution by Rancher | ||
|
||
|
||
## Remote cluster | ||
|
||
### Improve K8S command line UX | ||
|
||
- [kubectx+kubens](https://github.com/ahmetb/kubectx) : Fast way to switch between clusters and namespaces | ||
``` | ||
# Tip : easy merge kube config files and switch contexts | ||
export KUBECONFIG=~/.kube/k1_config:~/.kube/k2_config:~/.kube/k3_config | ||
kubectx | ||
<3 contexts> | ||
``` | ||
- [kube-shell](https://github.com/cloudnativelabs/kube-shell) : An integrated shell for working with the Kubernetes CLI | ||
- [kube-prompt](https://github.com/c-bata/kube-prompt) : An interactive kubernetes client featuring auto-complete | ||
- [K9S](https://github.com/derailed/k9s) : A terminal UI to interact with your Kubernetes clusters | ||
- [kube-ps1](https://github.com/jonmosco/kube-ps1) : Kubernetes prompt info for bash and zsh | ||
- [Stern](https://github.com/wercker/stern) : Multi pod and container log tailing | ||
- [Kail](https://github.com/boz/kail) : Kubernetes log viewer | ||
- [KubeSpy](https://github.com/pulumi/kubespy) : Tools for observing Kubernetes resources in real time | ||
``` | ||
kubectl create ns gd | ||
kubens gd | ||
# In one shell (keep it displayed) | ||
kubespy trace deploy gd/nginx-deployment | ||
# In another shell | ||
kubectl create -f https://k8s.io/examples/controllers/nginx-deployment.yaml | ||
# Pod | ||
kubespy status v1 Pod gd/nginx | ||
kubectl create -f https://github.com/pulumi/kubespy/raw/master/examples/trivial-pulumi-example/yaml/nginx.yaml | ||
# Service | ||
kubespy trace service gd/nginx | ||
kubectl create -f https://github.com/pulumi/kubespy/raw/master/examples/trivial-service-trace-example/yaml/nginx.yaml | ||
``` | ||
- [Kubectl plugins](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) | ||
- [Krew](https://github.com/GoogleContainerTools/krew) : Package manager for "kubectl plugins" | ||
- [Plugins index](https://github.com/GoogleContainerTools/krew-index/tree/master/plugins) | ||
``` | ||
kubectl krew {search,info,install,upgrade,remove} | ||
``` | ||
- Examples : | ||
- `kubectl view-utilization -h` | ||
- `kubectl get-all --only-scope=namespace --namespace=default` | ||
|
||
- [Arkade](https://github.com/alexellis/arkade) : helps you install kubernetes application with a single install command | ||
|
||
### Development | ||
|
||
- [kubefwd](https://github.com/txn2/kubefwd) : Bulk port forwarding Kubernetes services for local development | ||
- [Skaffolfd](https://github.com/GoogleContainerTools/skaffold) : Easy and Repeatable Kubernetes Development | ||
- [KSync](https://github.com/ksync/ksync) | ||
- [Telepresence](https://www.telepresence.io/) : Debug your Kubernetes service locally | ||
- [Tilt](https://tilt.dev/) : Manages local development instances for teams that deploy to Kubernetes | ||
- [KubeSquash](https://github.com/solo-io/kubesquash/blob/master/README.md) | ||
- [Kompose](http://kompose.io/) ([Conversion Matrix](https://github.com/kubernetes/kompose/blob/master/docs/conversion.md)) | ||
|
||
### GUI/TUI | ||
|
||
- [K8S Dashboard](https://github.com/kubernetes/dashboard) | ||
- [Kube-ops-view](https://github.com/hjacobs/kube-ops-view) : Read-only system dashboard for multiple K8s clusters | ||
- [K9S](https://github.com/derailed/k9s) | ||
- [Octant](https://octant.dev/docs/master/) | ||
- [Kubernetic](https://kubernetic.com/) | ||
- [k3x for k3d](https://github.com/inercia/k3x) | ||
- [Portainer](https://www.portainer.io/) : [Beta version](https://github.com/portainer/portainer-k8s) for Kubernetes | ||
- [KubeNav](https://github.com/kubenav/kubenav) | ||
- [Lens](https://github.com/lensapp/lens) | ||
- [Okteto](https://okteto.com/) | ||
|
||
## Other tools | ||
|
||
- [Dive](https://github.com/wagoodman/dive) | ||
|
||
## Chaos gaming tools 🕹 | ||
|
||
- [Kube Invaders](https://github.com/lucky-sideburn/KubeInvaders) | ||
- [Wild West Kubernetes](https://github.com/gshipley/wild-west-kubernetes) | ||
- [Kube Doom](https://github.com/storax/kubedoom) | ||
- [Kube Thanos](https://github.com/berkay-dincer/kubethanos) | ||
- [Kube Chaos](https://github.com/Shogan/kube-chaos) | ||
|
||
## Costing | ||
|
||
- [Kube Resource Report](https://github.com/hjacobs/kube-resource-report) | ||
``` | ||
kubereport () { | ||
mkdir -p /tmp/kubereport-output | ||
echo "" | ||
echo "----------------------------------------------------------" | ||
echo "Merging config files found in KUBECONFIG var..." | ||
echo "----------------------------------------------------------" | ||
echo $KUBECONFIG | sed 's/:/\n/g' | ||
echo "" | ||
echo "----------------------------------------------------------" | ||
kubectl config view --flatten > ~/.kube/config | ||
echo "Generating report..." | ||
echo "----------------------------------------------------------" | ||
docker pull hjacobs/kube-resource-report | ||
docker run -it --net=host -v ~/.kube/:/root/.kube/ -v /tmp/output:/output hjacobs/kube-resource-report /output | ||
echo "" | ||
echo "----------------------------------------------------------" | ||
echo "Opening report..." | ||
echo "----------------------------------------------------------" | ||
xdg-open /tmp/output/index.html & | ||
} | ||
``` | ||
- [KubeCost](https://kubecost.com/) | ||
|
||
## Learning | ||
|
||
- [Tutorials](https://kubernetes.io/docs/tutorials/) | ||
- [Playground](https://labs.play-with-k8s.com/) | ||
- [Katacoda](https://www.katacoda.com/courses/kubernetes) | ||
- [Official doc](https://kubernetes.io/docs/home/) | ||
- Comics | ||
- https://www.cncf.io/phippy/ | ||
- https://cloud.google.com/kubernetes-engine/kubernetes-comic/ | ||
- https://www.cncf.io/the-childrens-illustrated-guide-to-kubernetes/ | ||
- https://brennerm.github.io/posts/kubernetes-overview-diagrams.html | ||
- Zines | ||
|
||
![SceneFromK8S1](https://drawings.jvns.ca/drawings/scenes-from-kubernetes-page1.svg)![SceneFromK8S2](https://drawings.jvns.ca/drawings/scenes-from-kubernetes-page2.svg) | ||
|
||
![K8SComponents](https://pbs.twimg.com/media/DBzjTTKUIAA1OvE.jpg:small) | ||
|
||
## Useful links | ||
|
||
https://cloud.google.com/blog/products/containers-kubernetes/easier-kubernetes-development-from-your-laptop | ||
|
||
https://medium.com/@wso2tech/multi-node-kubernetes-cluster-with-vagrant-virtualbox-and-kubeadm-9d3eaac28b98 | ||
|
||
https://garden.slides.com/ellenkorbes/k8sdevtools?token=t3egVfZS#/38 | ||
|
||
https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0 | ||
|
||
https://ostechnix.com/kubernetes-features/ | ||
|
||
https://github.com/medmouine/Kubernetes-autoscaling-poster/blob/main/k8s-auto-scaling-poster.pdf |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# CLoud Code for VSCode | ||
|
||
## Intall | ||
|
||
Install it as a VSCode extension : https://github.com/GoogleCloudPlatform/cloud-code-vscode/releases | ||
|
||
## Demo | ||
|
||
Source : https://cloud.google.com/code/docs/vscode/ | ||
|
||
### Cloud Code View | ||
|
||
- GKE explorer : create cluster | ||
- Cluster Explorer : show minikube | ||
|
||
### Workflow | ||
|
||
- `Cloud Code > New Application` | ||
- initial files : https://cloud.google.com/code/docs/vscode/quickstart#whats_in_the_box | ||
- .vscode | ||
- K8S manifests | ||
- src | ||
- skaffold.yml | ||
- Continuous Deploy | ||
- Show deployment + service | ||
- Show container logs + Stream | ||
- Terminal into a pod | ||
- Debug (?) | ||
|
||
### K8S Explorer | ||
|
||
- Cluster info | ||
- Active cluster | ||
- Add secret as env var | ||
- Show logs | ||
- Decode secrets | ||
- On resource : Describe | ||
|
||
https://github.com/GoogleCloudPlatform/cloud-code-samples/tree/master/golang/go-hello-world |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Kind | ||
|
||
https://kind.sigs.k8s.io/ | ||
|
||
## Installation | ||
|
||
```bash | ||
./kind_install.sh [VERSION] | ||
``` | ||
|
||
## TL;DR | ||
|
||
```bash | ||
# 1 node cluster | ||
kind create cluster | ||
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" | ||
kubectl cluster-info | ||
|
||
# 3 masters + 3 workers cluster | ||
kind create cluster --confifg cplane-ha.yml | ||
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" | ||
kubectl cluster-info | ||
kubectl get nodes | ||
``` | ||
|
||
## Usage | ||
|
||
Create a kind cluster : | ||
|
||
```bash | ||
kind create cluster | ||
``` | ||
|
||
Interact with the cluster : | ||
|
||
```bash | ||
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" | ||
kubectl cluster-info | ||
``` | ||
|
||
Load a docker image in the cluster : | ||
|
||
```bash | ||
kind load docker-image my-custom-image | ||
``` | ||
|
||
Delete a kind cluster : | ||
|
||
```bash | ||
kind delete cluster | ||
``` | ||
|
||
## Configuring your kind cluster | ||
|
||
Is it possible to use a configuration file to customize your kind cluster (Multi-Node, Control-Plane HA...) | ||
|
||
```bash | ||
|
||
# Create a cluster with 3 control-plane nodes and 3 workers | ||
kind create cluster --config cplane-ha.yml | ||
|
||
# Create a cluster with 1 control-plane nodes and 3 workers | ||
kind create cluster --config multinode.yml | ||
|
||
``` | ||
|
||
See https://kind.sigs.k8s.io/docs/user/quick-start/#configuring-your-kind-cluster for details. | ||
|
||
## Auto Completion | ||
|
||
To enable completion : | ||
|
||
```bash | ||
# for bash users | ||
kind completion bash > ~/.kind-completion | ||
source ~/.kind-completion | ||
|
||
# for zsh users | ||
kind completion zsh > /usr/local/share/zsh/site-functions/_kind | ||
autoload -U compinit && compinit | ||
``` | ||
|
||
## Ingress with kind | ||
|
||
https://banzaicloud.com/blog/kind-ingress/ | ||
|
||
![Expose ports when deploying to kind](https://banzaicloud.com/img/blog/kind/kind-socat.png) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# a cluster with 3 control-plane nodes and 3 workers | ||
kind: Cluster | ||
apiVersion: kind.sigs.k8s.io/v1alpha3 | ||
nodes: | ||
- role: control-plane | ||
- role: control-plane | ||
- role: control-plane | ||
- role: worker | ||
- role: worker | ||
- role: worker |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
KIND_VERSION=${1:-"0.5.1"} | ||
curl -sLo kind https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-$(uname)-amd64 | ||
chmod +x kind | ||
sudo mv kind /usr/local/bin/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# three node (two workers) cluster config | ||
kind: Cluster | ||
apiVersion: kind.sigs.k8s.io/v1alpha3 | ||
nodes: | ||
- role: control-plane | ||
- role: worker | ||
- role: worker |
24 changes: 24 additions & 0 deletions
24
kubernetes-local-development/kubeadm-dind-cluster/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# kubeadm-dind-cluster | ||
|
||
## Install | ||
|
||
```bash | ||
KUBEADM_DIND_VERSION="v0.2.0" | ||
K8S_VERSION="v1.14" | ||
wget https://github.com/kubernetes-sigs/kubeadm-dind-cluster/releases/download/${KUBEADM_DIND_VERSION}/dind-cluster-${K8S_VERSION}.sh | ||
chmod +x dind-cluster-v1.14.sh | ||
``` | ||
|
||
## Run | ||
|
||
```bash | ||
sudo ./dind-cluster-v1.14.sh up | ||
``` | ||
|
||
## Stop and clean | ||
|
||
```bash | ||
#sudo systemctl stop kubelet | ||
sudo ./dind-cluster-v1.14.sh down | ||
sudo ./dind-cluster-v1.14.sh clean | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Minikube | ||
|
||
https://kubernetes.io/docs/setup/minikube/ | ||
|
||
## Installation | ||
|
||
```bash | ||
./minikube_install.sh | ||
``` | ||
|
||
## Usage | ||
|
||
To create a minikube cluster on VirtualBox, you have to use the `none` driver and some specific options. | ||
All these customizations have been automated in the following scripts : | ||
|
||
```bash | ||
./minikube_start.sh | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Alias to install & update minikube to the latest version | ||
function minikube_update() { | ||
curl -sLo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube | ||
} | ||
|
||
currentVersion=$(minikube update-check | grep Current | cut -d ' ' -f2) | ||
lastestVersion=$(minikube update-check | grep Latest | cut -d ' ' -f2) | ||
[[ "$currentVersion" != ${lastestVersion} ]] && minikube_update || echo "Already in latest version !" | ||
minikube version |
Oops, something went wrong.