Git Product home page Git Product logo

k8s-for-docker-desktop's Introduction

Docker Desktop for Mac/Windows 开启 Kubernetes

中文 | English

说明:

  • 需安装 Docker Desktop 的 Mac 或者 Windows 版本,如果没有请下载下载 Docker CE最新版本
  • 当前 master 分支已经在 Docker for Mac/Windows 2.0.5.x (包含 Docker CE 19.03.0 和 Kubernetes 1.14.3) 版本测试通过
    • 如果你希望使用 Docker for Mac/Windows 2.0.4.x (包含 Docker CE 18.09.1 和 Kubernetes 1.14.1) , 请使用下面命令切换 v1.14.1 分支 git checkout v1.14.1
    • 如果你希望使用 Docker for Mac/Windows 2.0.1.x/2.0.2.x/2.0.3.x (包含 Docker CE 18.09.1 和 Kubernetes 1.13.0) , 请使用下面命令切换 v2.0.1.0 分支 git checkout v2.0.1.0
    • 如果你希望使用 Docker for Mac/Windows 2.0.0.2/2.0.0.3 (包含 Docker CE 18.09.1 和 Kubernetes 1.10.11) , 请使用下面命令切换 v2.0.0.2 分支 git checkout v2.0.0.2
    • 如果你希望使用 18.09/18.06 版本(包含 Kubernetes 1.10.3) , 请使用下面命令切换 18.09 分支 git checkout 18.09
    • 如果你希望使用 18.03 版本, 请使用下面命令切换 18.03 分支 git checkout 18.03

查看 Docker Desktop版本,Docker -> About Docker Desktop about

Docker Desktop for Mac 开启 Kubernetes

为 Docker daemon 配置镜像加速,参考阿里云镜像服务 或中科大镜像加速地址https://docker.mirrors.ustc.edu.cn

mirror

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

resource

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

./load_images.sh

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

k8s

TIPS:如果在Kubernetes部署的过程中出现问题,可以通过docker desktop应用日志获得实时日志信息:

pred='process matches ".*(ocker|vpnkit).*"
  || (process in {"taskgated-helper", "launchservicesd", "kernel"} && eventMessage contains[c] "docker")'
/usr/bin/log stream --style syslog --level=debug --color=always --predicate "$pred"

Docker Desktop for Windows 开启 Kubernetes

为 Docker daemon 配置镜像加速,参考阿里云镜像服务 或使用中科大镜像加速地址 https://docker.mirrors.ustc.edu.cn

mirror

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

resource

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

使用 Bash shell

./load_images.sh

使用 PowerShell

 .\load_images.ps1

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

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

k8s

TIPS

  • 如果在Kubernetes部署的过程中出现问题,可以在 C:\ProgramData\DockerDesktop下的service.txt 查看Docker日志
  • 如果看到 Kubernetes一直在启动状态,请参考 Issue 3769(comment)Issue 1962(comment)

配置 Kubernetes

可选操作: 切换Kubernetes运行上下文至 docker-for-desktop (docker-ce 18.09 下 context 为 docker-desktop)

kubectl config use-context docker-for-desktop

验证 Kubernetes 集群状态

kubectl cluster-info
kubectl get nodes

部署 Kubernetes dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/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

配置 kubeconfig (可跳过)

对于Mac环境

TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"

对于Windows环境

$TOKEN=((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")[1]
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"

登录dashboard的时候选择 kubeconfig 文件

resource

选择 kubeconfig 文件,路径如下:

Mac: $HOME/.kube/config
Win: %UserProfile%\.kube\config

点击登陆,进入Kubernetes Dashboard

配置 Ingress

说明:如果测试 Istio,不需要安装 Ingress

安装 Ingress

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/cloud-generic.yaml

验证

kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx

测试示例应用

部署测试应用,详情参见社区文章

kubectl create -f sample/apple.yaml
kubectl create -f sample/banana.yaml
kubectl create -f sample/ingress.yaml

测试示例应用

$ curl -kL http://localhost/apple
apple
$ curl -kL http://localhost/banana
banana

删除示例应用

kubectl delete -f sample/apple.yaml
kubectl delete -f sample/banana.yaml
kubectl delete -f sample/ingress.yaml

删除 Ingress

kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/cloud-generic.yaml
kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

安装 Helm

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

在 Mac OS 上安装

通过 brew 安装

brew 安装的版本可能会和 helm server 不兼容, 如果在后续使用 helm 安装组件的过程中出现以下错误,可以 通过二进制包安装 对应的版本

$ helm install install/kubernetes/helm/istio-init --name istio-init --namespace istio-system
Error: incompatible versions client[v2.13.1] server[v2.12.2]
# 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.14.1 --skip-refresh

# Change helm repo
helm repo add stable http://mirror.azure.cn/kubernetes/charts-incubator/

# Update charts repo (Optional)
helm repo update
通过二进制包安装
# Download binary release
在 https://github.com/helm/helm/releases 中找到匹配的版本并下载(需要梯子), 如: https://storage.googleapis.com/kubernetes-helm/helm-v2.14.1-darwin-amd64.tar.gz

# Unpack

tar -zxvf helm-v2.0.0-linux-amd64.tgz

# Move it to its desired destination

mv darwin-amd64/helm /usr/local/bin/helm

在Windows上安装

如果在后续使用 helm 安装组件的过程中出现版本兼容问题,可以参考 通过二进制包安装 思路安装匹配的版本

# Use Chocolatey on Windows
# 注:安装的时候需要保证网络能够访问googleapis这个域名
choco install kubernetes-helm

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

# Change helm repo
helm repo add stable http://mirror.azure.cn/kubernetes/charts-incubator/

# Update charts repo (Optional)
helm repo update

配置 Istio

说明:Istio Ingress Gateway和Ingress缺省的端口冲突,请移除Ingress并进行下面测试

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

下载 Istio 1.1.1 并安装 CLI

curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.2 sh -
cd istio-1.2.2/
export PATH=$PWD/bin:$PATH

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

.\getLatestIstio.ps1

通过 Helm chart 安装 Istio

# 安装 istio-init chart 安装所有的 Istio CRD
helm install install/kubernetes/helm/istio-init --name istio-init --namespace istio-system

# 验证下安装的 Istio CRD 个数, 应该安装23个CRD
kubectl get crds | grep 'istio.io\|certmanager.k8s.io' | wc -l

# 开始 istio chart 安装
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://${GATEWAY_URL}/productpage

可以通过浏览器访问

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

删除实例应用

samples/bookinfo/platform/kube/cleanup.sh

卸载 Istio

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

k8s-for-docker-desktop's People

Contributors

denverdino avatar vallens avatar inouekonoha avatar zlzforever avatar 0x9be00ff1 avatar xiaods avatar siegrainwong avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.