关于k8s:如何使用-Kind-快速创建-K8s-集群

7次阅读

共计 2306 个字符,预计需要花费 6 分钟才能阅读完成。


作者|段超
起源|尔达 Erda 公众号

导读:Erda 作为一站式云原生 PaaS 平台,现已面向宽广开发者实现 70w+ 外围代码全副开源!在 Erda 开源的同时,咱们打算编写《基于 K8s 的云原生 PaaS 平台基础架构》系列文章,心愿咱们的一点教训能够帮忙更多企业欠缺 PaaS 平台基础架构的建设。

系列文章举荐:

  • 《系列好文 | Kubernetes 弃用 Docker,咱们该何去何从?》
  • 《我能够减肥失败,但我的 Docker 镜像肯定要瘦身胜利!》

Kind(Kubernets in Docker),是一个能够疾速在本地部署一套 K8s 的工具,非常适合本地部署调试或者想要体验最新版本 K8s 的场景。

简略创立

brew install kind
kind create cluster --name test

Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.13.4)  
 ✓ Preparing nodes   
 ✓ Creating kubeadm config   
 ✓ Starting control-plane  ️ 
Cluster creation complete. You can now use the cluster with:

[root@node-2 ~]# kubectl get node
NAME                 STATUS   ROLES    AGE   VERSION
kind-control-plane   Ready    master   99s   v1.13.4

默认会创立一个单节点的集群,想要创立更简单的集群?配置文件走起。

创立一个特定版本 K8s 的集群

配置文件

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4
- role: worker
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4
- role: worker
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4

创立集群

kind create cluster --name kind --config  cluster.yaml

其余版本的集群,其镜像列表见这里。

创立一个蕴含 Ingress 的集群

配置文件

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:  
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
- role: worker
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4
- role: worker
  image: kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4

  • extraPortMappings allow the local host to make requests to the Ingress controller over ports 80/443

创立集群

 kind create cluster --name kind-ingress --config  cluster.yaml

部署 Ingress

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

装置完后就能够在本地拜访 Ingress 了

curl http://127.0.0.1
curl -k https://127.0.0.1:443

可玩性

kind 采纳容器来模仿 node 节点,因而能够到容器外面进行 node 相干的操作,比方批改 kube-apiserver 的配置文件,查看 etcd 等。


如果对于 Erda 你有更多想要理解的内容,欢送增加小助手微信(Erda202106)进入交换群探讨,或者间接点击下方链接理解更多!

  • Erda Github 地址:https://github.com/erda-project/erda
  • Erda Cloud 官网:https://www.erda.cloud/
正文完
 0