K8S|让mac osx运行起一套k8s测试环境

作为k8s重度使用者,经常要写kubectl的测试脚本,而公司内网没有k8s环境,开放远程访问的话,又有诸多安全问题,不如在本机搭一套环境来的方便.
早先的时候,都是起几个虚拟机,弄套环境.忘记从哪个版本开始docker desktop也支持起动kubernetes了,五一闲来无事,用最新版本的docker-ce再趟一遍坑.

下载
首先肯定要有Docker Desktop for Mac
官方地址:
https://hub.docker.com/editions/community/docker-ce-desktop-mac
下载地址:
https://download.docker.com/mac/stable/Docker.dmg
当前最新版:2.2.0.5

开工
OSX任务栏->Docker图标->Preferences..->Kubernetes

勾选Enable Kubernetes,然后Apply & Restart

然后就是无尽的等待伴随风扇狂转了.退出docker再打开都不好使.当然硬气一点儿可以直接干掉docker,重新安装.
之所以卡在这,是因为Kubernetes启动需要以下依赖包

REPOSITORY                                                       TAG                 IMAGE ID            CREATED             SIZE
docker/desktop-storage-provisioner                               v1.0                605a0f683b7b        8 weeks ago         33.1MB
k8s.gcr.io/kube-proxy                                            v1.15.5             cbd7f21fec99        6 months ago        82.4MB
k8s.gcr.io/kube-controller-manager                               v1.15.5             1399a72fa1a9        6 months ago        159MB
k8s.gcr.io/kube-apiserver                                        v1.15.5             e534b1952a0d        6 months ago        207MB
k8s.gcr.io/kube-scheduler                                        v1.15.5             fab2dded59dd        6 months ago        81.1MB
quay.io/kubernetes-ingress-controller/nginx-ingress-controller   0.26.1              29024c9c6e70        7 months ago        483MB
docker/kube-compose-controller                                   v0.4.23             a8c3d87a58e7        11 months ago       35.3MB
docker/kube-compose-api-server                                   v0.4.23             f3591b2cb223        11 months ago       49.9MB
k8s.gcr.io/coredns                                               1.3.1               eb516548c180        15 months ago       40.3MB
k8s.gcr.io/kubernetes-dashboard-amd64                            v1.10.1             f9aed6605b81        16 months ago       122MB
k8s.gcr.io/etcd                                                  3.3.10              2c4adeb21b4f        17 months ago       258MB
k8s.gcr.io/pause                                                 3.1                 da86e6ba6ca1        2 years ago         742kB

k8s.gcr.io是个国外地址(国内不能访问,你懂的),怎么办呢?简单,已经的大拿帮我们解决过这个问题,还开源了,下面全场动作必须跟我整齐划一,来左边儿 跟我一起画个龙...

git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop
Cloning into 'k8s-for-docker-desktop'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 323 (delta 55), reused 51 (delta 25), pack-reused 232
Receiving objects: 100% (323/323), 2.55 MiB | 16.00 KiB/s, done.
Resolving deltas: 100% (185/185), done.

咱们docker配套的kubernetes是1.15.5所以还要切换一下

git checkout v1.15.5
Branch 'v1.15.5' set up to track remote branch 'v1.15.5' from 'origin'.
Switched to a new branch 'v1.15.5'

然后一通下载

./load_images.sh
images.properties found.
3.1: Pulling from google_containers/pause
cf9202429979: Pull complete
Digest: sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause@sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
...

当下载完成,你会发现风扇也不叫了.

完成安装了,接下来干点儿啥呢?

查看集群信息

kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

查看节点信息

kubectl get nodes
NAME             STATUS   ROLES    AGE   VERSION
docker-desktop   Ready    master   36d   v1.15.5

查看pod

kubectl get pod
No resources found.

查看服务

kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   36d

恭喜完成k8s环境搭建,后面想象空间很大哟~


相关博文

About rainbird

IOS攻城狮
This entry was posted in K8S and tagged , , , , , , , , , , , , . Bookmark the permalink.

发表评论