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
準備工作: Dockerfile、server.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/