Windows 10 docker fro desktop 安装k8s
Windows 10 docker fro desktop 安装k8s
Windows 10 docker fro desktop 安装k8s
-
首先配置Docker daemon 配置 Docker Hub 的中国官方镜像加速 https://registry.docker-cn.com 并开启 4GB 或更多内存
-
拉取镜像
1git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop
- 拉取k8s所需要的镜像 cd k8s-for-docker-desktop 可以通过修改 images.properties 文件加载你自己需要的镜像
1./load_images.ps1
说明: 如果因为安全策略无法执行 PowerShell 脚本,请在 “以管理员身份运行” 的 PowerShell 中执行 Set-ExecutionPolicy RemoteSigned 命令。我用的powershell core,非自带的ps
-
开启 Kubernetes
-
配置 Kubernetes 可选操作: 切换Kubernetes运行上下文至 docker-desktop
1kubectl config use-context docker-desktop
验证 Kubernetes 集群状态
1kubectl cluster-info
2kubectl get nodes
- 部署 Kubernetes dashboard https://github.com/kubernetes/dashboard
1kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
2
3开启 API Server 访问代理
4kubectl proxy
5
6访问:http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
配置 kubeconfig
1$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]
2kubectl config set-credentials docker-desktop --token="${TOKEN}"
3
4
5config 路径
6%UserProfile%\.kube\config
7
8注意如果出现:Not enough data to create auth info structure.
9
101. 网上
11kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
12
13配置kube的config文件,将刚才生成的token: 放在最后。( token: 后面有个空格 ,不然会报:错误)
14
15kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
162. 如果config文件中有token,则复制token,点击令牌登录
Kuboard 是基于一款基于 Kubernetes 的微服务管理面板
1安装
2kubectl apply -f https://kuboard.cn/install-script/kuboard.yaml
3
4获取token(所以权限)通过git执行命令
5kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}')
6
7只读用户 的 Token 通过git执行命令
8kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep kuboard-viewer | awk '{print $1}')
9
10访问Kuboard
11
121. Kuboard Service 使用了 NodePort 的方式暴露服务,NodePort 为 32567;您可以按如下方式访问 Kuboard。
13http://任意一个Worker节点的IP地址:32567/
14
152. 或者
16kubectl port-forward service/kuboard 8080:80 -n kube-system
17
18在浏览器打开链接 (请使用 kubectl 所在机器的IP地址)
19
20http://localhost:8080
- 配置 Ingress
https://www.cnblogs.com/linuxk/p/9706720.html
说明:如果测试 Istio,不需要安装 Ingress
1kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
2
3kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
4
5验证:
6kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx
测试示例应用 部署测试应用,详情参见社区文章
1kubectl create -f sample/apple.yaml
2kubectl create -f sample/banana.yaml
3kubectl create -f sample/ingress.yaml
测试示例应用
1$ curl -kL http://localhost/apple
2apple
3$ curl -kL http://localhost/banana
4banana
删除示例应用
1kubectl delete -f sample/apple.yaml
2kubectl delete -f sample/banana.yaml
3kubectl delete -f sample/ingress.yaml
删除 Ingress
1kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
2kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
1如果在后续使用 helm 安装组件的过程中出现版本兼容问题,可以参考 通过二进制包安装 思路安装匹配的版本
2
3# Use Chocolatey on Windows
4# 注:安装的时候需要保证网络能够访问googleapis这个域名
5choco install kubernetes-helm
6
7# Install Tiller into your Kubernetes cluster
8helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.14.1 --skip-refresh
9
10# Change helm repo
11helm repo add stable http://mirror.azure.cn/kubernetes/charts-incubator/
12
13# Update charts repo (Optional)
14helm repo update
通过二进制包安装
1# Download binary release
2在 https://github.com/helm/helm/releases 中找到匹配的版本并下载(需要梯子), 如: https://storage.googleapis.com/kubernetes-helm/helm-v2.14.1-darwin-amd64.tar.gz
3
4# Unpack
5
6tar -zxvf helm-v2.0.0-linux-amd64.tgz
7
8# Move it to its desired destination
9
10mv darwin-amd64/helm /usr/local/bin/helm
- 配置 Istio (待验证) 说明:Istio Ingress Gateway和Ingress缺省的端口冲突,请移除Ingress并进行下面测试 可以根据文档安装 Istio https://istio.io/docs/setup/kubernetes/
9.1 通过 下载 Istio 1.2.4 并安装 CLI
1curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.4 sh -
2cd istio-1.2.4/
3export PATH=$PWD/bin:$PATH
在Windows上,您可以手工下载Istio安装包,或者把getLatestIstio.ps1拷贝到你希望下载 Istio 的目录,并执行 - 说明:根据社区提供的安装脚本修改而来
1getLatestIstio.ps1
2
3param(
4 [string] $IstioVersion = "0.3.0"
5)
6
7$url = "https://github.com/istio/istio/releases/download/$($IstioVersion)/istio_$($IstioVersion)_win.zip"
8$Path = Get-Location
9$output = [IO.Path]::Combine($Path, "istio_$($IstioVersion)_win.zip”)
10
11Write-Host "Downloading Istio from $url to path " $Path -ForegroundColor Green
12
13#Download file
14(New-Object System.Net.WebClient).DownloadFile($url, $output)
15
16# Unzip the Archive
17Expand-Archive $output -DestinationPath $Path
18
19#Set the environment variable
20$IstioHome = [IO.Path]::Combine($Path, "istio-$($IstioVersion)")
21
22[Environment]::SetEnvironmentVariable("ISTIO_HOME", "$IstioHome", "User")
23
1.\getLatestIstio.ps1
9.2 通过 Helm chart 安装 Istio
1# 安装 istio-init chart 安装所有的 Istio CRD
2helm install install/kubernetes/helm/istio-init --name istio-init --namespace istio-system
3
4# 验证下安装的 Istio CRD 个数, 应该安装23个CRD
5kubectl get crds | grep 'istio.io\|certmanager.k8s.io' | wc -l
6
7# 开始 istio chart 安装
8helm install install/kubernetes/helm/istio --name istio --namespace istio-system
查看 istio 发布状态
1helm status istio
为 default 名空间开启自动 sidecar 注入
1kubectl label namespace default istio-injection=enabled
2kubectl get namespace -L istio-injection
安装 Book Info 示例
1kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
2kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
确认示例应用在运行中
1export GATEWAY_URL=localhost:80
2curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage
可以通过浏览器访问
http://localhost/productpage
说明:如果当前80端口已经被占用或保留,我们可以编辑 install/kubernetes/helm/istio/values.yaml 文件中 Gateway 端口进行调整,比如将 80 端口替换为 8888 端口
1 ## You can add custom gateway ports
2 - port: 8888 # Changed from 80
3 targetPort: 80
4 name: http2
5 nodePort: 31380
然后执行如下命令并生效
1kubectl delete service istio-ingressgateway -n istio-system
2helm upgrade istio install/kubernetes/helm/istio
删除实例应用
1samples/bookinfo/platform/kube/cleanup.sh
卸载 Istio
1helm del --purge istio
2kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
Minikube 安装k8s
https://yq.aliyun.com/articles/221687
centos7 安装单机版k8s
安装集群:手动安装
https://github.com/yonyoucloud/install_k8s https://github.com/unixhot/salt-k8s