How to do local development with Kubernetes?

2019-01-30 03:42发布

Kubernetes seems to be all about deploying containers to a cloud of clusters. What it doesn't seem to touch is development and staging environments (or such).

During development you want to be as close as possible to production environment with some important changes:

  • Deployed locally (or at least somewhere where you and only you can access)
  • Use latest source code on page refresh (supposing its a website; ideally page auto-refresh on local file save which can be done if you mount source code and use some stuff like Yeoman).

Similarly one may want a non-public environment to do continuous integration.

Does Kubernetes support such kind of development environment or is it something one has to build, hoping that during production it'll still work?

10条回答
戒情不戒烟
2楼-- · 2019-01-30 04:13

The disadvantage of using minkube is that it spawns another virtual machine over your machine. Also, with latest minikube version it minimum requires to have 2 CPU and 2GB of RAM from your system, which makes it pretty heavy If you do not have the system with enough resources.

This is the reason I switched to microk8s for development on kubernetes and I love it. microk8s supports the DNS, local-storage, dashboard, istio, ingress and many more, everything you need to test your microservices.

It is designed to be a fast and lightweight upstream Kubernetes installation isolated from your local environment. This isolation is achieved by packaging all the binaries for Kubernetes, Docker.io, iptables, and CNI in a single snap package.

A single node kubernetes cluster can be installed within a minute with a single command:

snap install microk8s --classic

Make sure your system doesn't have any docker or kubelet service running. Microk8s will install all the required services automatically.

Please have a look at the following link to enable other add ons in microk8s.

https://github.com/ubuntu/microk8s

You can check the status using:

velotio@velotio-ThinkPad-E470:~/PycharmProjects/k8sClient$ microk8s.status
microk8s is running
addons:
ingress: disabled
dns: disabled
metrics-server: disabled
istio: disabled
gpu: disabled
storage: disabled
dashboard: disabled
registry: disabled
查看更多
ら.Afraid
3楼-- · 2019-01-30 04:15

Update (2016-07-15)

With the release of Kubernetes 1.3, Minikube is now the recommended way to run Kubernetes on your local machine for development.


You can run Kubernetes locally via Docker. Once you have a node running you can launch a pod that has a simple web server and mounts a volume from your host machine. When you hit the web server it will read from the volume and if you've changed the file on your local disk it can serve the latest version.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-30 04:22

You can use a remote kubernetes cluster and configure your local machines to connect to this cluster. Use kubectl cp commands to copy code to running pods for hot reload of code during development.

查看更多
▲ chillily
5楼-- · 2019-01-30 04:25

See https://github.com/kubernetes/kubernetes/issues/12278 for how to mount a volume from the host machine, the equivalent of:

docker run -v hostPath:ContainerPath
查看更多
登录 后发表回答