Added configure kubeconfig credentials section.

pull/5/head
Allen.Cai 6 years ago committed by Allen.Cai
parent 98c493ba1a
commit 589924e547

@ -20,7 +20,7 @@
预先从阿里云Docker镜像服务下载 Kubernetes 所需要的镜像, 可以通过修改 ```images.properties``` 文件加载你自己需要的镜像 预先从阿里云Docker镜像服务下载 Kubernetes 所需要的镜像, 可以通过修改 ```images.properties``` 文件加载你自己需要的镜像
``` ```bash
./load_images.sh ./load_images.sh
``` ```
@ -44,13 +44,13 @@
使用 Bash shell 使用 Bash shell
``` ```bash
./load_images.sh ./load_images.sh
``` ```
使用 PowerShell 使用 PowerShell
``` ```powershell
.\load_images.ps1 .\load_images.ps1
``` ```
@ -67,32 +67,32 @@
可选操作: 切换Kubernetes运行上下文至 docker-for-desktop 可选操作: 切换Kubernetes运行上下文至 docker-for-desktop
``` ```shell
kubectl config use-context docker-for-desktop kubectl config use-context docker-for-desktop
``` ```
验证 Kubernetes 集群状态 验证 Kubernetes 集群状态
``` ```shell
kubectl cluster-info kubectl cluster-info
kubectl get nodes kubectl get nodes
``` ```
部署 Kubernetes dashboard 部署 Kubernetes dashboard
``` ```shell
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
``` ```
``` ```shell
kubectl create -f kubernetes-dashboard.yaml kubectl create -f kubernetes-dashboard.yaml
``` ```
开启 API Server 访问代理 开启 API Server 访问代理
``` ```shell
kubectl proxy kubectl proxy
``` ```
@ -100,20 +100,36 @@ kubectl proxy
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default
### 配置 kubeconfig
```bash
$ TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"
```
#### 选择 kubeconfig 文件
![resource](images/k8s_credentials.png)
选择 kubeconfig 文件,路径如下:
Win: %UserProfile%\.kube\config
Mac: $HOME/.kube/config
点击登陆进入Kubernetes Dashboard
### 配置 Ingress ### 配置 Ingress
说明:如果测试 Istio不需要安装 Ingress 说明:如果测试 Istio不需要安装 Ingress
#### 安装 Ingress #### 安装 Ingress
``` ```shell
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/cloud-generic.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/cloud-generic.yaml
``` ```
验证 验证
``` ```shell
kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx
``` ```
@ -123,7 +139,7 @@ kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx
部署测试应用,详情参见[社区文章](https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-ingress-guide-nginx-example.html) 部署测试应用,详情参见[社区文章](https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-ingress-guide-nginx-example.html)
``` ```shell
kubectl create -f sample/apple.yaml kubectl create -f sample/apple.yaml
kubectl create -f sample/banana.yaml kubectl create -f sample/banana.yaml
kubectl create -f sample/ingress.yaml kubectl create -f sample/ingress.yaml
@ -131,7 +147,7 @@ kubectl create -f sample/ingress.yaml
测试示例应用 测试示例应用
``` ```bash
$ curl -kL http://localhost/apple $ curl -kL http://localhost/apple
apple apple
$ curl -kL http://localhost/banana $ curl -kL http://localhost/banana
@ -140,7 +156,7 @@ banana
删除示例应用 删除示例应用
``` ```shell
kubectl delete -f sample/apple.yaml kubectl delete -f sample/apple.yaml
kubectl delete -f sample/banana.yaml kubectl delete -f sample/banana.yaml
kubectl delete -f sample/ingress.yaml kubectl delete -f sample/ingress.yaml
@ -148,7 +164,7 @@ kubectl delete -f sample/ingress.yaml
#### 删除 Ingress #### 删除 Ingress
``` ```shell
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/provider/cloud-generic.yaml
kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
``` ```
@ -159,7 +175,7 @@ kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/mas
#### 在 Mac OS 上安装 #### 在 Mac OS 上安装
``` ```shell
# Use homebrew on Mac # Use homebrew on Mac
brew install kubernetes-helm brew install kubernetes-helm
@ -172,7 +188,7 @@ helm repo update
#### 在Windows上安装 #### 在Windows上安装
``` ```shell
# Use Chocolatey on Windows # Use Chocolatey on Windows
choco install kubernetes-helm choco install kubernetes-helm
@ -192,7 +208,7 @@ helm repo update
#### 下载 Istio 1.0.4 并安装 CLI #### 下载 Istio 1.0.4 并安装 CLI
``` ```bash
curl -L https://git.io/getLatestIstio | sh - curl -L https://git.io/getLatestIstio | sh -
cd istio-1.0.4/ cd istio-1.0.4/
export PATH=$PWD/bin:$PATH export PATH=$PWD/bin:$PATH
@ -200,7 +216,7 @@ export PATH=$PWD/bin:$PATH
在Windows上您可以手工下载Istio安装包或者把```getLatestIstio.ps1```拷贝到你希望下载 Istio 的目录,并执行 - 说明:根据社区提供的[安装脚本](https://gist.github.com/kameshsampath/796060a806da15b39aa9569c8f8e6bcf)修改而来 在Windows上您可以手工下载Istio安装包或者把```getLatestIstio.ps1```拷贝到你希望下载 Istio 的目录,并执行 - 说明:根据社区提供的[安装脚本](https://gist.github.com/kameshsampath/796060a806da15b39aa9569c8f8e6bcf)修改而来
``` ```powershell
.\getLatestIstio.ps1 .\getLatestIstio.ps1
``` ```
@ -208,26 +224,26 @@ export PATH=$PWD/bin:$PATH
#### 通过 Helm chart 安装 Istio #### 通过 Helm chart 安装 Istio
``` ```shell
helm install install/kubernetes/helm/istio --name istio --namespace istio-system helm install install/kubernetes/helm/istio --name istio --namespace istio-system
``` ```
#### 查看 istio 发布状态 #### 查看 istio 发布状态
``` ```shell
helm status istio helm status istio
``` ```
#### 为 ```default``` 名空间开启自动 sidecar 注入 #### 为 ```default``` 名空间开启自动 sidecar 注入
``` ```shell
kubectl label namespace default istio-injection=enabled kubectl label namespace default istio-injection=enabled
kubectl get namespace -L istio-injection kubectl get namespace -L istio-injection
``` ```
#### 安装 Book Info 示例 #### 安装 Book Info 示例
``` ```shell
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
``` ```
@ -235,7 +251,7 @@ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
确认示例应用在运行中 确认示例应用在运行中
``` ```bash
export GATEWAY_URL=localhost:80 export GATEWAY_URL=localhost:80
curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage
``` ```
@ -258,20 +274,20 @@ Gateway 端口进行调整,比如将 80 端口替换为 8888 端口
然后执行如下命令并生效 然后执行如下命令并生效
``` ```shell
kubectl delete service istio-ingressgateway -n istio-system kubectl delete service istio-ingressgateway -n istio-system
helm upgrade istio install/kubernetes/helm/istio helm upgrade istio install/kubernetes/helm/istio
``` ```
#### 删除实例应用 #### 删除实例应用
``` ```bash
samples/bookinfo/platform/kube/cleanup.sh samples/bookinfo/platform/kube/cleanup.sh
``` ```
### 卸载 Istio ### 卸载 Istio
``` ```shell
helm del --purge istio helm del --purge istio
kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
``` ```

@ -18,7 +18,8 @@ Optional: config the CPU and memory for Kubernetes, 4GB RAM or more is suggested
Preload Kubernetes images form Alibaba Cloud Registry Service, NOTE: you can modify the ```images.properties``` for your own images Preload Kubernetes images form Alibaba Cloud Registry Service, NOTE: you can modify the ```images.properties``` for your own images
```
```bash
./load_images.sh ./load_images.sh
``` ```
@ -42,13 +43,13 @@ Preload Kubernetes images form Alibaba Cloud Registry Service, NOTE: you can mod
In Bash shell In Bash shell
``` ```bash
./load_images.sh ./load_images.sh
``` ```
or in PowerShell of Windows or in PowerShell of Windows
``` ```powershell
.\load_images.ps1 .\load_images.ps1
``` ```
@ -64,52 +65,70 @@ Enable Kubernetes in Docker for Windows, and wait a while for Kubernetes is runn
Optional: switch the context to docker-for-desktop Optional: switch the context to docker-for-desktop
```
```shell
kubectl config use-context docker-for-desktop kubectl config use-context docker-for-desktop
``` ```
Verify Kubernetes installation Verify Kubernetes installation
``` ```shell
kubectl cluster-info kubectl cluster-info
kubectl get nodes kubectl get nodes
``` ```
Deploy Kubernetes dashboard Deploy Kubernetes dashboard
```shell
```
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
``` ```
or or
``` ```shell
kubectl create -f kubernetes-dashboard.yaml kubectl create -f kubernetes-dashboard.yaml
``` ```
Start proxy for API server Start proxy for API server
``` ```shell
kubectl proxy kubectl proxy
``` ```
Access dashboard Access Kubernetes dashboard
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default
#### Config kubeconfig
![resource](images/k8s_credentials.png)
```bash
$ TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-for-desktop --token="${TOKEN}"
```
#### Choose kubeconfig file
![resource](images/k8s_credentials.png)
Choose kubeconfig file, Path
Win: %UserProfile%\.kube\config
Mac: $HOME/.kube/config
Click login, go to Kubernetes Dashboard
### Install Helm ### Install Helm
Install helm following the instruction on https://github.com/helm/helm/blob/master/docs/install.md Install helm following the instruction on https://github.com/helm/helm/blob/master/docs/install.md
``` ```shell
# Use homebrew on Mac # Use homebrew on Mac
brew install kubernetes-helm brew install kubernetes-helm
# Install Tiller into your Kubernetes cluster # Install Tiller into your Kubernetes cluster
helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --skip-refresh
# update charts repo # update charts repo (Optional)
helm repo update helm repo update
``` ```
@ -117,50 +136,50 @@ helm repo update
More details can be found in https://istio.io/docs/setup/kubernetes/ More details can be found in https://istio.io/docs/setup/kubernetes/
Download Istio 1.0.3 and install CLI Download Istio 1.0.4 and install CLI
``` ```bash
curl -L https://git.io/getLatestIstio | sh - curl -L https://git.io/getLatestIstio | sh -
cd istio-1.0.3/ cd istio-1.0.4/
export PATH=$PWD/bin:$PATH export PATH=$PWD/bin:$PATH
``` ```
Install Istio with Helm chart Install Istio with Helm chart
``` ```shell
helm install install/kubernetes/helm/istio --name istio --namespace istio-system helm install install/kubernetes/helm/istio --name istio --namespace istio-system
``` ```
Check status of istio release Check status of istio release
``` ```shell
helm status istio helm status istio
``` ```
Enable automatic sidecar injection for ```default``` namespace Enable automatic sidecar injection for ```default``` namespace
``` ```shell
kubectl label namespace default istio-injection=enabled kubectl label namespace default istio-injection=enabled
kubectl get namespace -L istio-injection kubectl get namespace -L istio-injection
``` ```
Install Book Info sample Install Book Info sample
``` ```shell
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
Confirm application is running Confirm application is running
``` ```bash
export GATEWAY_URL=localhost:80 export GATEWAY_URL=localhost:80
curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage
``` ```
Delete Istio Delete Istio
``` ```shell
helm del --purge istio helm del --purge istio
kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
``` ```

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Loading…
Cancel
Save