[kubernetes learning notes] - using minikube to quickly deploy k8s single machine learning environment

It fat 2020-11-09 23:48:33
kubernetes learning notes using minikube


Introduce

Minikube For fast local setup Kubernetes Single node cluster environment , It does not require too much hardware resources , It is convenient for developers to learn and try , Or daily development .

It supports most of kubernetes The function of , The list is as follows

  • DNS
  • NodePorts
  • ConfigMaps and Secrets
  • Dashboards
  • Container Runtime: Docker, and rkt
  • Enabling CNI (Container Network Interface)
  • Ingress
  • ...

Minikube Support Windows、macOS、Linux Three OS, Depending on the platform , Download the corresponding virtual machine image , And install it in the mirror k8s.

The current virtual machine technology is based on Hypervisor To achieve ,Hypervisor A unified virtual layer interface is defined , thus Minikube You can seamlessly switch between different virtual machine implementations , Such as macOS Switchable hyperkit or VirtualBox, Windows You can switch Hyper-V or VirtualBox etc. .

Virtual machine switching can be done through --vm-driver Realization , Such as minikube start --vm-driver hyperkit/ minikube start --vm-driver hyperv

If Minikube Installed in the kernel, it supports LXC Of OS Inside , Such as Ubuntu etc. , Installing the virtual machine again is obviously a waste of resources ,Minikube Provides direct docking OS The way down there

  • driver!=none mode

    In this case minikube provisions a new docker-machine (Docker daemon/Docker host) using any supported providers. For instance: a) local provider = your Windows/Mac local host: it frequently uses VirtualBox as a hypervisor, and creates inside it a VM based on boot2docker image (configurable). In this case k8s bootstraper (kubeadm) creates all Kubernetes components inside this isolated VM. In this setup you have usually two docker daemons, your local one for development (if you installed it prior), and one running inside minikube VM. b) cloud hosts - not supported by minikube

  • driver=none mode

    In this mode, your local docker host is re-used. In case no.1 there will be a performance penalty, because each VM generates some overhead, by running several system processes required by VM itself, in addition to those required by k8s components running inside VM. I think driver-mode=none is similar to " HYPERLINK "https://blog.alexellis.io/be-kind-to-yourself/"kind" version of k8s boostraper, meant for doing CI/integration tests.

Minikube install

download Minikube

curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.13.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

download Kubectl

curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

start-up Minikube

Launch parameters

Start command :minikube start " Parameters "

- --image-mirror-country cn Will default to use registry.cn-hangzhou.aliyuncs.com/google_containers As an installation Kubernetes The container image warehouse of ,
- --iso-url=*** Use Alibaba cloud's image address to download the corresponding .iso file
- --cpus=2: by minikube Virtual machine allocation CPU Check the number
- --memory=2000mb: by minikube The number of memory allocated by the virtual machine
- --kubernetes-version=***: minikube Virtual machines will use kubernetes edition ,e.g. --kubernetes-version v 1.17.3
- --docker-env http_proxy Delivery agent address
The default startup uses VirtualBox drive , Use --vm-driver Parameters can specify other drivers
# https://minikube.sigs.k8s.io/docs/drivers/
- --vm-driver=none It means to use a container ;
- --vm-driver=virtualbox It means virtual machine ;

Be careful : To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:

 sudo mv /root/.kube /root/.minikube $HOME
sudo chown -R $USER $HOME/.kube $HOME/.minikube

Example

--vm-driver=kvm2

Reference resources : https://minikube.sigs.k8s.io/docs/drivers/kvm2/

minikube start --image-mirror-country cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --registry-mirror=https://ovfftd6p.mirror.aliyuncs.com --driver=kvm2

--vm-driver=hyperv
# Create based on Hyper-V Of Kubernetes Test environment
minikube.exe start --image-mirror-country cn \
--iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.5.0.iso \
--registry-mirror=https://xxxxxx.mirror.aliyuncs.com \
--vm-driver="hyperv" \
--hyperv-virtual-switch="MinikubeSwitch" \
--memory=4096
--vm-driver=none

sudo minikube start --image-mirror-country cn --vm-driver=none

minikube-install

sudo minikube start --vm-driver=none --docker-env http_proxy=http://$host_IP:8118 --docker-env https_proxy=https:// $host_IP:8118

among $host_IP refer to host Of IP, Can pass ifconfig see ; For example, my machine is 10.0.2.15, use virtualbox Deploy , Start with the following command minikube

sudo minikube start --vm-driver=none --docker-env http_proxy=http://10.0.2.15:8118 --docker-env https_proxy=https://10.0.2.15:8118

Minikube Status view

To start over , Will run a single node Kubernetes colony .Minikube Have also put kubectl Good configuration , So you don't have to do extra work to manage the container .
Minikube Create a Host-Only( Host only mode ) Network interface , Through this interface, you can route to nodes . If you want to run with pods or services Interact , You should send traffic through this address . Use minikube ip The command can view this address :

minikube-status

Minikube Use

The user to use Minikube CLI Manage... On virtual machines Kubernetes Environmental Science , such as : start-up , stop it , Delete , Get status, etc . once Minikube Virtual machine start , Users can use familiar Kubectl CLI stay Kubernetes Perform operations on the cluster

# View all the resources in the cluster
kubectl get all
# Enter the node server
minikube ssh
# Execute node server commands , For example, view nodes docker info
minikube ssh -- docker info
# Delete cluster , Delete ~/.minikube Directory cached files
minikube delete
# Shut down the cluster
minikube stop
## Destroy cluster
minikube stop && minikube delete

Minikube plug-in unit

sudo minikube addons list

Minikube Integrated by default Kubernetes Dashboard. perform minikube dashboard After the command , The browser will open by default

minikube-dashboard

Installation problems

problem -1

Failed to save config: failed to acquire lock for /root/.minikube/profiles/minikube/config.json: unable to open /tmp/juju-mk270d1b5db5965f2dc9e9e25770a63417031943: permission denied

terms of settlement :

sudo rm -rf /tmp/juju-mk*
sudo rm -rf /tmp/minikube.*

problem -2

unable to read client-cert /root/.minikube/client.crt for minikube due to open /root/.minikube/client.crt: permission denied
unable to read client-key /root/.minikube/client.key for minikube due to open /root/.minikube/client.key: permission denied
unable to read certificate-authority /root/.minikube/ca.crt for minikube due to open /root/.minikube/ca.crt: permission denied

terms of settlement :

minikube stop
minikube delete
rm -rf ~/.kube
rm -rf ~/.minikube
sudo rm -rf /var/lib/minikube
sudo rm /var/lib/kubeadm.yaml
sudo rm -rf /etc/kubernetes

Reference resources :https://stackoverflow.com/questions/58541104/minikube-wont-work-after-ubuntu-upgrade-to-19-10

problem -3

Error restarting cluster: restarting kube-proxy: waiting for kube-proxy to be up for configmap update: timed out waiting for the condition

adopt minikube delete,minikube start Can solve

Deploy the application

$ kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
deployment.apps/hello-minikube created
# To access the application
$ kubectl expose deployment hello-minikube --type=NodePort
service/hello-minikube exposed
# Get service address
$ minikube service hello-minikube --url
http://192.168.99.105:30555

Reference material

  1. Minikube - Kubernetes Local experimental environment
  2. Hello Minikube
  3. Running Kubernetes Locally via Minikube
  4. Install Minikube
版权声明
本文为[It fat]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云