其他分享
首页 > 其他分享> > kind快速部署k8s测试集群(在docker中运行)

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

作者:互联网

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

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

cat > kind.yaml << EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  apiServerAddress: "192.168.192.139"
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.139:8080

  

  

 

 

 

 

鸣谢:

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

标签:kubectl,kind,cluster,--,yaml,nginx,docker,k8s
来源: https://www.cnblogs.com/yakniu/p/16436186.html