https://docs.docker.com/docker-for-windows/kubernetes/
根据官方文档docker开始支持kubenete了,我下载的是18.03.0-ce版本
C:\e\docker\Hello-Call>docker version
Client:
Version: 18.03.0-ce-rc1
API version: 1.37
Go version: go1.9.4
Git commit: c160c73 Built: Thu Feb 22 02:34:04 2018
OS/Arch: windows/amd64
Experimental: true
Orchestrator: kubernetes
Server:
Engine:
Version: 18.03.0-ce-rc1
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: c160c73
Built: Thu Feb 22 02:42:37 2018
OS/Arch: linux/amd64
Experimental: true
安装docker后,进入docker的setting页面,你就会发现kubenetes的页面,
需要说明的是,有很多image在国内访问时不行的。需要设置代理。
我使用的是shadowsocks代理,默认的设置不行的,需要开启Allow clients from LAN选项,如下图
这样就会在第一图片的右下角看见docker和kubenetes都是running状态了
默认情况下,dashboard是没有安装的。
C:\e\docker\Hello-Call>kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
docker compose-5d4f4d67b6-7v2fn 1/1 Running 2 2h
docker compose-api-7bb7b5968f-lq87s 1/1 Running 2 2h
kube-system etcd-docker-for-desktop 1/1 Running 4 2h
kube-system kube-apiserver-docker-for-desktop 1/1 Running 4 2h
kube-system kube-controller-manager-docker-for-desktop 1/1 Running 4 2h
kube-system kube-dns-6f4fd4bdf-kjmgp 3/3 Running 14 2h
kube-system kube-proxy-rwwd8 1/1 Running 4 2h
kube-system kube-scheduler-docker-for-desktop 1/1 Running 4 2h
解压附件中dashboard.zip文件,然后运行kubectl create -f dashboard.yaml,然后再次查看pods列表,已经有dashboard了.
C:\e\docker\Hello-Call>kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-call-74954c79d6-6pxqk 1/1 Running 0 14m
default hello-node-9f5f775d6-fcx7r 1/1 Running 0 1h
docker compose-5d4f4d67b6-7v2fn 1/1 Running 2 2h
docker compose-api-7bb7b5968f-lq87s 1/1 Running 2 2h
kube-system etcd-docker-for-desktop 1/1 Running 4 2h
kube-system kube-apiserver-docker-for-desktop 1/1 Running 4 2h
kube-system kube-controller-manager-docker-for-desktop 1/1 Running 4 2h
kube-system kube-dns-6f4fd4bdf-kjmgp 3/3 Running 14 2h
kube-system kube-proxy-rwwd8 1/1 Running 4 2h
kube-system kube-scheduler-docker-for-desktop 1/1 Running 4 2h
kube-system kubernetes-dashboard-576dbb7658-hk9lr 1/1 Running 0 59m
查看访问dashboard的port,是32145.然后访问http://localhost:32145
C:\e\docker\Hello-Call>kubectl get services kubernetes-dashboard -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes-dashboard NodePort 10.96.186.156 <none> 80:32145/TCP 1h
接下来部署两个服务,代码请参考services.zip
Hello-node : 返回 hello world
Hello-call: 调用hello-node服务,同样返回hello world :)就是为了测试cluster根据DNS的调用是否好用!
1 - build两个镜像
docker build -t hello-node:v1 .
docker build -t hello-call:v2 .
2 - 部署deployment
kubectl run hello-node --image=hello-node:v1 --port=8080
kubectl run hello-call --image=hello-call:v2 --port=8085
3 - 暴露service
kubectl expose deployment hello-node --type=LoadBalancer
kubectl expose deployment hello-call --type=LoadBalancer
C:\e\docker\Hello-Call>kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-call LoadBalancer 10.99.2.54 localhost 8085:30502/TCP 28m
hello-node LoadBalancer 10.109.90.135 localhost 8080:32680/TCP 1h
hello-call和hello-node可以单独调用,
hello-node = http://localhost:8080
>>>Hello World!
hello-call = http://localhost:8085
>>>data from rest api: Hello World!
最后上传一张dashboard的截图:
上面通过service的dashboard,启动后,在pod中有如下错误,有时间再去研究。
2018/05/14 10:04:35 Metric client health check failed: the server could not find the requested resource (get services heapster). Retrying in 30 seconds.
通过如下方法启动dashboard:
https://github.com/kubernetes/dashboard/
1 -
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
2 -
kubectl proxy
3 -
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
4 - token ->skip
部署ingress(Docker for Mac),没有for windows,只能在git bash中安装。
https://kubernetes.github.io/ingress-nginx/deploy/#verify-installation
imgess yaml
C:/System32/driver/etc/hosts
me 127.0.0.1
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/ssl-redirect: "true"
ingress.kubernetes.io/secure-backends: "true"
ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
tls:
- hosts:
- me
secretName: tls-certificate
rules:
- host: me
http:
paths:
- path: /taxonomy_application
backend:
serviceName: taxonomy-application
servicePort: 9080