# 使用帮助 [root@Ansible ~]# kind -h kind creates and manages local Kubernetes clusters using Docker container 'nodes'
Usage: kind [command]
Available Commands: build Build one of [node-image] completion Output shell completion code for the specified shell (bash, zsh or fish) create Creates one of [cluster] delete Deletes one of [cluster] export Exports one of [kubeconfig, logs] get Gets one of [clusters, nodes, kubeconfig] help Help about any command load Loads images into nodes version Prints the kind CLI version
Flags: -h, --help help for kind --loglevel string DEPRECATED: see -v instead -q, --quiet silence all stderr output -v, --verbosity int32 info log verbosity, higher value produces more output --version version for kind
Use "kind [command] --help" for more information about a command. # 下载部署所需的容器镜像 [root@Ansible ~]# docker pull kindest/node:v1.27.3 # 使用预制kind配置信息,通过阿里云代理镜像 [root@Kind ~]# cat kind-config.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta1 kind: ClusterConfiguration metadata: name: config networking: serviceSubnet: 10.96.0.0/12 podSubnet: 10.244.0.0/16 disableDefaultCNI: false imageRepository: registry.aliyuncs.com/google_containers nodeRegistration: kubeletExtraArgs: pod-infra-container-image: registry.aliyuncs.com/google_containers/pause:3.9 nodes: - role: control-plane
[root@Ansible ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION ansible-control-plane Ready control-plane 4m32s v1.27.3
[root@Kind ~]# kubectl get ns NAME STATUS AGE default Active 3m56s kube-node-lease Active 3m56s kube-public Active 3m56s kube-system Active 3m56s local-path-storage Active 3m49s
# 部署一个nginx的pod [root@Kind ~]# kubectl run pod1 --image=nginx --image-pull-policy=IfNotPresent pod/pod1 created # 查看日志输出 [root@Kind ~]# kubectl logs pod1 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2023/10/17 04:59:39 [notice] 1#1: using the "epoll" event method 2023/10/17 04:59:39 [notice] 1#1: nginx/1.25.2 2023/10/17 04:59:39 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14) 2023/10/17 04:59:39 [notice] 1#1: OS: Linux 5.14.0-284.30.1.el9_2.x86_64 2023/10/17 04:59:39 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1073741816:1073741816 2023/10/17 04:59:39 [notice] 1#1: start worker processes 2023/10/17 04:59:39 [notice] 1#1: start worker process 35 2023/10/17 04:59:39 [notice] 1#1: start worker process 36 2023/10/17 04:59:39 [notice] 1#1: start worker process 37 2023/10/17 04:59:39 [notice] 1#1: start worker process 38 # 部署一个deployment,副本设为3 [root@Kind ~]# kubectl create deployment web1 --image=nginx --replicas=3 # 查看部署结果 [root@Kind ~]# kubectl get pods NAME READY STATUS RESTARTS AGE pod1 1/1 Running 0 7m26s web1-c5d84d68d-5x9ng 1/1 Running 0 2m5s web1-c5d84d68d-pgzp4 1/1 Running 0 2m5s web1-c5d84d68d-xz78k 1/1 Running 0 2m21s [root@Kind ~]# kubectl get deployments.apps NAME READY UP-TO-DATE AVAILABLE AGE web1 3/3 3 3 2m30s # 将ds使用80端口发布为服务 [root@Kind ~]# kubectl expose deployment web1 --name=svc1 --port=80 --type=NodePort service/svc1 exposed # 容器的30403端口转发到Node的80端口 [root@Kind ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 18m svc1 NodePort 10.96.235.184 <none> 80:30403/TCP 3m11s # 实现端口转发 [root@Kind ~]# kubectl port-forward services/svc1 8080:80 Forwarding from 127.0.0.1:8080 -> 80 Forwarding from [::1]:8080 -> 80 Handling connection for 8080 # 默认只能转发到127.0.0.1且大于3000以上的端口 [root@Kind ~]# curl 127.0.0.1:8080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>