创建新的 K8s 集群
创建 config.yaml使用 kind create cluster 重新创建集群:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
由于示例应用使用了 Ingress,所以我们需要为 Kind 部署 Ingress,你可以使用 kubectl apply -f 来部署 Ingress-Nginx:
❯ kind create cluster --config config.yaml
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.23.4) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
$ kubectl create -f https://ghproxy.com/ https://raw.githubusercontent.com/lyzhang1999/resource/main/ingress-nginx/ingress-nginx.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
serviceaccount/ingress-nginx-admission created
......
:::color2 Ingress controller(Ingress 控制器)是面向 Kubernetes(及其他容器化)环境的专用负载均衡器。
Kubernetes Ingress Controller 的功能如下:- 接受来自 Kubernetes 平台外部的流量,并将其负载均衡到 Kubernetes 平台内部运行的 pod(容器)
- 可管理集群内需要与集群外其他服务通信的服务的出向流量
- 使用 Kubernetes API 进行配置,以部署名为“Ingress 资源”的对象
- 监控 Kubernetes 中运行的 pod,并在服务添加或删除 pod 后自动更新负载均衡规则
:::