Kubenetes on Docker

本文详细介绍如何在Docker 18.03版本中配置并使用Kubernetes,包括设置代理、部署服务、安装和配置Kubernetes Dashboard以及创建Ingress等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值