kind快速部署k8s测试集群(在docker中运行)

继前面使用kind快速搭建本地k8s集群介绍

编写配置文件,注意修改apiserver监听地址

cat > kind.yaml << EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  apiServerAddress: "192.168.192.140"
containerdConfigPatches:
- |-
  [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
    endpoint = ["registry.aliyuncs.com/google_containers"]
EOF

 

 

安装cluster

kind create cluster --config kind.yaml

 

 

 

 

安装好后集群配置文件位置

~/.kube/config

 

 

若权限不够,运行如下指令

  

 

切换 kubectl 集群上下文

kubectl cluster-info --context kind-kind

  

部署nginx

cat > nginx.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
  - name: 80-tcp
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
EOF

  

运行

kubectl create -f nginx.yaml

 

 

 

查看

kubectl get pod,svc

 

 

kubectl port-forward --address 0.0.0.0 service/nginx 8080:80 

 

 

   

查看页面

curl -s http://192.168.192.140:8080

 浏览器访问

 

若浏览器访问不了

1.停止firewalld服务
systemctl stop firewalld
2.禁用firewalld服务
systemctl mask firewalld

 

删除集群

kind delete cluster

 

 

删除所有集群

如果你想一次性删除所有集群,请执行:

kind delete clusters --all

 

 

 

 

鸣谢

https://blog.csdn.net/Jailman/article/details/121249579

https://blog.csdn.net/aodamao/article/details/117292308

posted @ 2022-07-01 22:56  春光牛牛  阅读(211)  评论(0编辑  收藏  举报