Tutorial : Getting Started with Kubernetes on your Windows Laptop with Minikube

來源:互聯網
上載者:User

https://rominirani.com/tutorial-getting-started-with-kubernetes-on-your-windows-laptop-with-minikube-3269b54a226#.d9lmuvzf2


本文的注意事項:

1, 截止到2017.01.20, window上的kubernetes依然是實驗性的, 存在各種不可預知的bug, 如果遇到bug, 請到kubernetes的github上搜尋issues來尋找解決辦法( Issues · kubernetes/kubernetes  https://github.com/kubernetes/kubernetes/issues )

2, 截止到2017.01.20, 在操作下面教程的時候要注意, 各種命令操作請在管理員權限的cmd或prowerShell下進行, 然後切換到C盤(系統硬碟), 如果在其他盤操作會失敗, 這是已知的當前bug

3, 文中會提示安裝Docker-toolbox, 它會自動安裝所有docker, docker-compose, virtualbox等環境, 要安裝到C盤(系統硬碟), 其他盤的安裝會引起bug

4, 文中會提示把kubectl , minikube, etcd放到$PATH路徑中, 記得放到系統硬碟的路徑中, 最好是C盤根目錄, 然後把根目錄添加到系統內容$PATH中

5, 在啟動kubernetes時, 運行minikube start命令, 可能提示"xxx machine not found", 這種錯誤在issues中找到是因為上述安裝的virtualbox, minikube, docker, 當前操作的cmd的工作目錄等不是在C盤, 所以安裝時候請按照上述提示安裝; 如果提示"xxx fail", 很有可能是因為使用的docker-toolbox來安裝virtualbox的版本跟minikube和win10的版本不匹配, 建議到virtualbox官網下載最新的virtualbox版本 ( Downloads – Oracle VM VirtualBox  https://www.virtualbox.org/wiki/Downloads )


I have recently covered multiple posts (1 & 2)on getting started with Docker Swarm.

I personally like the simplicity of Docker Swarm and have found in my teaching experience with developers, that it was easier for most people to understand what Container Management solutions are all about when they see a few simple commands in Docker Swarm and are able to relate to stuff like scaling up/down, rolling updates, etc.

Personally I think if you are looking for a container management solution in today’s world, you have to invest your time in Kubernetes (k8s). There is no doubt about that because of multiple factors. To the best of my undestanding, these points include: Kubernetes is Open Source Great momentum in terms of activities & contribution at its Open Source Project Decades of experience running its predecessor at Google Support of multiple OS and infrastructure software vendors Rate at which features are being released Production readiness (Damn it, Pokemon Go met its scale due to Kubernetes) Number of features available. Check out the list of features at the home page. What this post is about?

I do not want to spend time explaining about what Kubernetes is and its building blocks like Pods, Replication Controllers, Services, Deployments and more. There are multiple articles on that and I suggest that you go through it.

I have written a couple of other articles that go through a high level overview of Kubernetes: Introduction to Kubernetes Kubernetes Building Blocks

It is important that you go through some basic material on its concepts, so that we can directly get down into its commands.

The general perception about a management solution like Kubernetes is that it would require quite a bit of setup for you to try it out locally. What this means is that it would take some time to set it up but more than setting it up, you might probably get access to it only during staging phase or something like that. Ideally you want a similar environment in your development too, so that you are as close to what it takes to run your application. The implications of this is that you want it running on your laptop/desktop, where you are likely to do your development.

This was the goal behind the minikube project and the team has put in fantastic effort to help us setup and run Kubernetes on our development machines. This is as simple and portable as it can get. The tagline of minikube project says it all: “Run Kubernetes locally”.
Side Note: The  design of the minikube logo makes for interesting reading.

This post is going to take you through setting up Minikube on your Windows development machine and then taking it for a Hello World spin to see a local Kubernetes cluster in action. Along the way, I will highlight my environment and what I had to do to get the experimental build of minikube working on my Windows machine. Yes, it is experimental software, but it works!

If you are not on Windows, the instructions to setup minikube on either your Linux machine or Mac machine are also available here. Check it out. You can then safely skip over the setup and go to the section where we do a quick Hello World to test drive Kubernetes locally.

Keep in mind that Minikube gives you a single node cluster that is running in a VM on your development machine. Of course, once you are done with what you see in this blog, I strongly recommend that you also look at Managed Container Orchestration solutions like Google Container Engine.

Let’s get started now with installation of minikube. But first, we must make sure that our development machine has some of the pre-requisites required to run it. Do not ignore that! Using VirtualBox and not Hyper-V

VirtualBox and Hyperv (which is available on Windows 10) do not make a happy pair and you are bound to run into situations where the tools get confused. I preferred to use VirtualBox and avoid all esoteric command-line switches that we need to provide to enable creation of the underlying Docker hosts, etc.

To disable Hyper-V, go to Turn Windows features on or off and you will see a dialog with list of Windows features as shown below. Navigate to the Hyper-V section and disable it completely. This will require a restart to the machine to take effect and on my machine, it even ended up doing a Windows Update, configuring it and a good 10 minutes later, it was back up.

Great! We have everything now to get going. Development Machine Environment

I am assuming that you have a setup that is similar to this. I believe, you should be fine on Windows 7 too and it would not have the HyperV stuff, instructions of which I will give in a while. Windows 10 Laptop. VT-x/AMD-v virtualization must be enabled in BIOS. Docker Toolbox v1.12.0. The toolbox sets up VirtualBox and I have gone with that. kubectl command line utility. This is the CLI utility for the Kubernetes cluster and you need to install it and have it available in your PATH. To install the latest 1.4 release, do the following: Go to the browser and give the following URL : http://storage.googleapis.com/kubernetes-release/release/v1.4.0/bin/windows/amd64/kubectl.exe. This will download the kubectl CLI executable. Please make it available in the environment PATH variable. Note: kubectl versions are available at a generic location as per the following format:  https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/${GOOS}/${GOARCH}/${K8S_BINARY} Minikube installation

The first step is to take the kubectl.exe file that you downloaded in the previous step and place that in the C:\ folder.

The next step is to download the minikube binary from the following location: https://github.com/kubernetes/minikube/releases

Go to the Windows download link as shown below:

This will start downloading the v0.10.0 release of the executable. The file name is minikube-windows-amd64.exe. Just rename this to minikube.exeand place it in C:\ drive, alongside the kubectl.exe file from the previous section.

You are all set now to launch a local Kubernetes one-node cluster!

All the steps moving forward are being done in Powershell. Launch Powershell in Administrative mode (Ctrl-Shift-Enter) and navigate to C:\ drive where the kubectl.exe and minikube.exe files are present. A few things to note

Let’s do our standard testing to validate our utilities.

If you go to your %HOMEPATH%\.minikube folder now, you will notice that several folders got created. Take a look!

There are multiple commands that Minikube supports. You can use the standard ` — help` option to see the list of commands that it has:

PS C:\> .\minikube --helpMinikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows
Usage:  minikube [command]
Available Commands:  dashboard        Opens/displays the kubernetes dashboard URL for your local cluster  delete           Deletes a local kubernetes cluster.  docker-env       sets up docker env variables; similar to '$(docker-machine env)'  get-k8s-versions Gets the list of available kubernetes versions available for minikube.  ip               Retrieve the IP address of the running cluster.  logs             Gets the logs of the running localkube instance, used for debugging minikube, not user code.  config           Modify minikube config  service          Gets the kubernetes URL for the specified service in your local cluster  ssh              Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'  start            Starts a local kubernetes cluster.  status           Gets the status of a local kubernetes cluster.  stop             Stops a running local kubernetes cluster.  version          Print the version of minikube.
Flags:      --alsologtostderr[=false]: log to standard error as well as files      --log-flush-frequency=5s: Maximum number of seconds between log flushes      --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace      --log_dir="": If non-empty, write log files in this directory      --logtostderr[=false]: log to standard error instead of files      --show-libmachine-logs[=false]: Whether or not to show logs from libmachine.      --stderrthreshold=2: logs at or above this threshold go to stderr      --v=0: log level for V logs      --vmodule=: comma-separated list of pattern=N settings for file-filtered logging
Use "minikube [command] --help" for more information about a command.

I have highlighted a couple of Global flags that you can use in all the commands for minikube. These flags are useful to see what is going on inside the hood at times and also for seeing the output on the standard output (console/command).

Minikube supports multiple versions of Kubernetes and the latest version is v1.4.0. To check out the different versions supported try out the following command:

PS C:\> .\minikube get-k8s-versionsThe following Kubernetes versions are available:        - v1.4.0        - v1.3.7        - v1.3.6        - v1.3.5        - v1.3.4        - v1.3.3        - v1.3.0
Starting our Cluster

We are now ready to launch our Kubernetes cluster locally. We will use thestart command for it.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.