Windows 下使用 Minikube 搭建Kubernetes


Windows 下使用 Minikube 搭建Kubernetes

#硬件要求:

  • 2核CPU或更高配置
  • 2GB内存或更高配置
  • 20GB磁盘空间或更多
  • 连接互联网
  • 容器或虚拟机管理器,例如:Docker、Hyperkit、Hyper-V、KVM、Parallels、Podman、VirtualBox 或 VMware Fusion/Workstation

#Windows下使用PowerShell安装

New-Item -Path 'd:\' -Name 'minikube' -ItemType Directory -Force
Invoke-WebRequest -OutFile 'd:\minikube\minikube.exe' -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe' -UseBasicParsing

其中路径可以自定义

【——全网最全的网络安全学习资料包分享给爱学习的你,关注我,私信回复“领取”获取——】

1.网络安全多个方向学习路线

2.全网最全的CTF入门学习资料

3.一线大佬实战经验分享笔记

4.网安大厂面试题合集

5.红蓝对抗实战技术秘籍

6.网络安全基础入门、Linux、web安全、渗透测试方面视频

设置环境变量

$oldPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)
if ($oldPath.Split(';') -inotcontains 'd:\minikube'){ `
  [Environment]::SetEnvironmentVariable('Path', $('{0};d:\minikube' -f $oldPath), [EnvironmentVariableTarget]::Machine) `
}

#启动集群

minikube start
Windows 下使用 Minikube 搭建Kubernetes

默认情况下会使用Hyperv作为驱动

如果要使用Vmware或者其他,启动的时候需要指定

minikube start --driver vmware
Windows 下使用 Minikube 搭建Kubernetes

如果报Exiting due to PROVIDER_VMWARE_NOT_FOUND: The 'vmware' provider was not found: exec: "vmrun": executable file not found in $PATH信息,把vmware的安装路径加入系统环境变量就行。

Windows 下使用 Minikube 搭建Kubernetes

下载安装docker-machine-driver-vmware

https://github.com/machine-drivers/docker-machine-driver-vmware/releases/latest

下载然后放到系统中的任何位置都可以,但要把路径配置到环境变量中

再次启动

国内指定国内源:

--image-mirror-country=cn --image-repository=registry.cn-hangzhou.ali
yuncs.com/google_containers
Windows 下使用 Minikube 搭建Kubernetes

启动成功

#部署应用

创建应用YAML描述文件,这里以Nginx为例

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

基于YAML文件创建部署

E:\>minikube kubectl -- apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created

查看部署信息:

minikube kubectl -- describe deployment nginx-deployment
Windows 下使用 Minikube 搭建Kubernetes

#暴露应用访问

查看 ReplicaSet 对象的信息:

E:\>minikube kubectl -- get replicasets
NAME                         DESIRED   CURRENT   READY   AGE
nginx-deployment-9456bbbf9   2         2         2       17m

E:\>minikube kubectl -- describe replicasets
Windows 下使用 Minikube 搭建Kubernetes

创建公开 Deployment 的 Service 对象:

minikube kubectl -- expose deployment nginx-deployment --type=NodePort --name=web-servicevice
service/web-servicevice exposed

查看Service信息:

E:\>minikube kubectl -- get service web-servicevice
NAME              TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
web-servicevice   NodePort   10.98.221.134           80:30074/TCP   30s
Windows 下使用 Minikube 搭建Kubernetes

查看 Service详情:

minikube kubectl -- describe services web-servicevice
Name:                     web-servicevice
Namespace:                default
Labels:                   
Annotations:              
Selector:                 app=nginx
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.98.221.134
IPs:                      10.98.221.134
Port:                       80/TCP
TargetPort:               80/TCP
NodePort:                   30074/TCP
Endpoints:                172.17.0.5:80,172.17.0.6:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   

这里因为用了NodePort的方式暴露外部服务,记住这个端口

查看IP列表:

E:\>minikube kubectl -- get nodes -o wide
NAME       STATUS   ROLES                  AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE              KERNEL-VERSION   CONTAINER-RUNTIME
minikube   Ready    control-plane,master   77m   v1.23.3   192.168.91.140           Buildroot 2021.02.4   4.19.202         docker://20.10.12

使用INTERNAL-IP加上NodePort的端口就可以访问应用了

curl http://http://:
Windows 下使用 Minikube 搭建Kubernetes

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章