window 10 中k8s安装与解析,以及helloword部署

mac2024-06-28  54

Windows10  pro安装 k8s

环境检查:

环境检查,确保自己的电脑版本是 Windows10  pro,避免出现bug。

如果你是 Windows10  家庭版,请升级到对应版本。

https://blog.csdn.net/hce1478506318/article/details/80863274

2.安装k8s

下载安装包并安装:

https://minikube.sigs.k8s.io/docs/start/windows/

安装完成后,下载对应国内阿里云镜像。

下载 minikube-windows-amd64.exe 文件,并重命名为 minikube.exe,并替换原来的镜像

下载链接:

https://github.com/kubernetes/minikube/releases/download/v0.22.3/minikube-installer.exe

初始化配置:

    1.用管理员权限打开 Windows PowerShell

    systeminfo     如果出现:           Hyper-V Requirements:     VM Monitor Mode Extensions: Yes                           Virtualization Enabled In Firmware: Yes                           Second Level Address Translation: Yes                           Data Execution Prevention Available: Yes       Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All       Hyper-V 配置完成。

2.创建minikube

// 启动minikube 指定虚拟机 hyperv     minikube start --vm-driver=hyperv      // 设置默认启动 虚拟机     minikube config set vm-driver hyperv     // 设置minikube 占用内存     minikube config set memory 4096     // 访问minikube集群中运行的Kubernetes仪表板:     minikube dashboard

初始化完成,下面我们做个简单的案例吧!

    1.hello word

准备工作: Dockerfileserver.js

  Dockerfile:

FROM node:6.9.2 EXPOSE 8080 COPY server.js . CMD node server.js server.js var http = require('http'); var handleRequest = function(request, response) { console.log('Received request for URL: ' + request.url); response.writeHead(200); response.end('Hello World!'); }; var www = http.createServer(handleRequest); www.listen(8080);

制作docker镜像:

      docker build -t hello:v1 .

    运行:

第一种方式:

kubectl run hello --image=hello:v1 --port=9999 --replicas=2 kubectl expose deployment hello --type=LoadBalancer --port=9999

第二种方式:通过配置文件启动

hello-deployment.yaml

apiVersion: apps/v1 kind: Deployment metadata: name: hello labels: app: hello spec: replicas: 2 # 部署的份数 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: hello image: hello:v1 ports: - containerPort: 9999 # 对应容器内部的端口

hello-Service.yaml

apiVersion: v1 kind: Service metadata: name: hello spec: type: LoadBalancer selector: app: hello ports: - protocol: TCP port: 9999 targetPort: 9999

部署与暴漏端口:

kubectl apply -f .\hello-deployment.yaml

kubectl apply -f .\hello-Service.yaml

更新镜像:

kubectl set image deployment/hello-node hello-node=hello-node:v2

现在,您可以清理在集群中创建的资源: 

kubectl delete deployment hello  

kubectl delete service hello

3.参考资料:

     安装:

    https://learnk8s.io/blog/installing-docker-and-kubernetes-on-windows/

demo案例

      https://kubernetes.io/docs/tutorials/hello-minikube/

问题错误解析:

1.切换docker环境:

minikube docker-env | Invoke-Expression (只能在当前大的窗口有用,关闭或者重新开启其他的命令窗口没有作用)

2.查看docker 环境。

minikube docker-env

 

3.部署完成后外网无法访问的问题:

   有很多的中原因造成的,我仅仅踩了一种:这个两个端口保持一致。

 

4. Failed to pull image “car/configuration:latest”: rpc error: code = Unknown desc = Error response from daemon: pull access denied for car/configuration, repository does not exist or may require ‘docker login’

https://www.bitdoom.com/2018/08/13/p145/

 

 

最新回复(0)