温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎样在笔记本上搭建Kubernetes+Istio开发环境

发布时间:2021-12-10 17:20:29 来源:亿速云 阅读:115 作者:柒染 栏目:云计算

本篇文章为大家展示了怎样在笔记本上搭建Kubernetes+Istio开发环境,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

说明:文章测试通过环境 Docker CE 18.09 (Kubernetes 1.10.3) 以及 Istio 1.0.4

先决条件,你需要一个 Docker for Mac或者Docker for Windows的安装包,如果没有请下载下载 Docker CE最新版本。由于Kubernetes大量的容器镜像在 gcr.io, 无法在国内保证稳定的访问。我们提供了一些工具脚本,帮助从阿里云镜像服务下载所需镜像

首先,

git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop
cd k8s-for-docker-desktop

Docker for Mac 开启 Kubernetes

为 Docker daemon 配置 Docker Hub 的中国官方镜像加速 https://registry.docker-cn.com

可选操作: 为 Kubernetes 配置 CPU 和 内存资源,建议分配 4GB 或更多内存。

怎样在笔记本上搭建Kubernetes+Istio开发环境cdn.com/61ae11ebd5b54db875390a1f2a5f36c6a4a32154.png">

预先从阿里云Docker镜像服务下载 Kubernetes 所需要的镜像, 可以通过修改 images.properties 文件加载你自己需要的镜像

./load_images.sh

开启 Kubernetes,并等待 Kubernetes 开始运行

Docker for Windows 开启 Kubernetes

为 Docker daemon 配置 Docker Hub 的中国官方镜像加速 https://registry.docker-cn.com

怎样在笔记本上搭建Kubernetes+Istio开发环境

可选操作: 为 Kubernetes 配置 CPU 和 内存资源,建议分配 4GB 或更多内存。

预先从阿里云Docker镜像服务下载 Kubernetes 所需要的镜像, 可以通过修改 images.properties 文件加载你自己需要的镜像

使用 Bash shell

./load_images.sh

使用 PowerShell

 .\load_images.ps1

说明: 如果因为安全策略无法执行 PowerShell 脚本,请在 “以管理员身份运行” 的 PowerShell 中执行 Set-ExecutionPolicy RemoteSigned 命令。

开启 Kubernetes,并等待 Kubernetes 开始运行

怎样在笔记本上搭建Kubernetes+Istio开发环境

配置 Kubernetes

可选操作: 切换Kubernetes运行上下文至 docker-for-desktop

kubectl config use-context docker-for-desktop

验证 Kubernetes 集群状态

kubectl cluster-info
kubectl get nodes

部署 Kubernetes dashboard

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

kubectl create -f kubernetes-dashboard.yaml

开启 API Server 访问代理

kubectl proxy

通过如下 URL 访问 Kubernetes dashboard

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default

说明:如果测试 Istio,不需要安装 Ingress,如果需要 Ingress 可以参考 https://github.com/AliyunContainerService/k8s-for-docker-desktop 中 Ingress相关章节

安装 Helm

可以根据文档安装 helm https://github.com/helm/helm/blob/master/docs/install.md

在 Mac OS 上安装
# Use homebrew on Mac
brew install kubernetes-helm

# Install Tiller into your Kubernetes cluster
helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --skip-refresh

# update charts repo (Optional)
helm repo update
在Windows上安装
# Use Chocolatey on Windows
choco install kubernetes-helm

# Install Tiller into your Kubernetes cluster
helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --skip-refresh

# update charts repo (Optional)
helm repo update

配置 Istio

可以根据文档安装 Istio https://istio.io/docs/setup/kubernetes/

下载 Istio 1.0.4 并安装 CLI
curl -L https://git.io/getLatestIstio | sh -
cd istio-1.0.4/
export PATH=$PWD/bin:$PATH

在Windows上,您可以手工下载Istio安装包,或者把getLatestIstio.ps1拷贝到你希望下载 Istio 的目录,并执行 - 说明:根据社区提供的安装脚本修改而来

.\getLatestIstio.ps1
通过 Helm chart 安装 Istio
helm install install/kubernetes/helm/istio --name istio --namespace istio-system
查看 istio 发布状态
helm status istio
default 名空间开启自动 sidecar 注入
kubectl label namespace default istio-injection=enabled
kubectl get namespace -L istio-injection
安装 Book Info 示例
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

确认示例应用在运行中

export GATEWAY_URL=localhost:80
curl -o /dev/null -s -w "%{http_code}\n">

可以通过浏览器访问

http://localhost/productpage

说明:如果当前80端口已经被占用或保留,我们可以编辑 install/kubernetes/helm/istio/values.yaml 文件中
Gateway 端口进行调整,比如将 80 端口替换为 8888 端口

      ## You can add custom gateway ports
    - port: 8888  # Changed from 80
      targetPort: 80
      name: http2
      nodePort: 31380

然后执行如下命令并生效

kubectl delete service istio-ingressgateway -n istio-system
helm upgrade istio install/kubernetes/helm/istio
学习 Istio

大家参照 Istio 开始学习吧, https://istio.io/zh/docs/examples/bookinfo/

怎样在笔记本上搭建Kubernetes+Istio开发环境

删除实例应用
samples/bookinfo/platform/kube/cleanup.sh

卸载 Istio

helm del --purge istio
kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system

上述内容就是怎样在笔记本上搭建Kubernetes+Istio开发环境,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI