K8s Kind使用

简单使用下kind

环境:rhel9.2

kubectl

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
sudo yum install -y kubectl
echo "exclude=kubectl" >> /etc/dnf/dnf.conf
kubectl version --output=yaml # 打印版本信息,当前为v1.27.3

版本信息如下:(因为cluster还没起来,所以没有server的信息

clientVersion:
  buildDate: "2023-06-14T09:53:42Z"
  compiler: gc
  gitCommit: 25b4e43193bcda6c7328a6d147b1fb73a33f1598
  gitTreeState: clean
  gitVersion: v1.27.3
  goVersion: go1.20.5
  major: "1"
  minor: "27"
  platform: linux/amd64
kustomizeVersion: v5.0.1

The connection to the server localhost:8080 was refused - did you specify the right host or port?

kind

安装kind

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind --version # 当前版本为0.20.0

创建cluster

yum install -y podman # 安装podman
kind create cluster --name demo --wait 5m 
# 使用默认的node image创建cluster。https://hub.docker.com/r/kindest/node/。 
# kind 版本和镜像版本有对应关系,在release页面查看 https://github.com/kubernetes-sigs/kind/releases

输出:

enabling experimental podman provider
Creating cluster "demo" ...
 ✓ Ensuring node image (kindest/node:v1.27.3) 🖼 
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Waiting ≤ 5m0s for control-plane = Ready ⏳ 
 • Ready after 17s 💚
Set kubectl context to "kind-demo"
You can now use your cluster with:

kubectl cluster-info --context kind-demo

Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community

此时,查看podman的容器列表,可以看到:

# podman ps
CONTAINER ID  IMAGE                                                                                           COMMAND     CREATED        STATUS        PORTS                      NAMES
6313438e57a5  docker.io/kindest/node@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72              5 minutes ago  Up 5 minutes  127.0.0.1:39025->6443/tcp  demo-control-plane

使用kubectl查看cluster信息:

# kubectl version --output=yaml
clientVersion:
  buildDate: "2023-06-14T09:53:42Z"
  compiler: gc
  gitCommit: 25b4e43193bcda6c7328a6d147b1fb73a33f1598
  gitTreeState: clean
  gitVersion: v1.27.3
  goVersion: go1.20.5
  major: "1"
  minor: "27"
  platform: linux/amd64
kustomizeVersion: v5.0.1
serverVersion:
  buildDate: "2023-06-15T00:36:28Z"
  compiler: gc
  gitCommit: 25b4e43193bcda6c7328a6d147b1fb73a33f1598
  gitTreeState: clean
  gitVersion: v1.27.3
  goVersion: go1.20.5
  major: "1"
  minor: "27"
  platform: linux/amd64

# kubectl cluster-info         
Kubernetes control plane is running at https://127.0.0.1:39025
CoreDNS is running at https://127.0.0.1:39025/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

再看看 ~/.kube/config 集群配置文件:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJek1EY3hPREV5TXpNME0xb1hEVE16TURjeE5URXlNek0wTTFvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTUFECjdUWUhB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3UxbHFJNlFjQVd4Ryt0RFlweVE4SVIzOWxpSzUxNnI3c2lPSmRDWnM3T0dudy9EaVMKL2xJPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://127.0.0.1:39025
  name: kind-demo
contexts:
- context:
    cluster: kind-demo
    user: kind-demo
  name: kind-demo
current-context: kind-demo
kind: Config
preferences: {}
users:
- name: kind-demo
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJSVd1TEZtRlFEY3N3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBM01UZ3hNak16TkROYUZ3MHlOREEzTVRjeE1qTXpORFZhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXZtd0phU3FCeGhkWnhPUlYKaSsvckpMdDdxallXN0FXZGptc0NYNmxxM2EvVVNMbHNwYU0rYitISTVUcnJ4RnRSd2gwQXI0cVRTRnZiNnh0cwpuM3VTbnNUMFlDOGkxWWxUTnVzbExxVjJyYVlZQzF5c2ZQMVBsTnl5ZEJlUU90ZHNBWEhuOExtUEJZN2tpaEFjCjdDU0dpTUdxWFppS1U4QXRpVXZ6RzZmV1ZjTjliTDNjQ1BoaEtiWE96ZzBDM3dXMkZTczBWMHVXc0ttMjcvWEEKTlR3NkZneE9scndoTkRiRVVxZFJoUmpmSHNGT01mQVVScjhTRUs2LzhrQ2c2bzhmUlQ1cUtwTkVzNzdnZTE1dApQUkNqWmhJemJRQ3BFVUIxZERvMW5BUndDeWZiQ2pCd0RkU1ViYWk3RkJwd0pleThYcWQwcFBCaThOU2ZTb0RCCktxLytNd0lEQVFBQm8x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ScEMvbWhwSm04dHh5CkNXWkI1R0oyd09ZWWcrc1NvVjFmZnJNUitBejM4TEpTbkpMMkNTVUNnWUJ2WnVCdDFkUTJJUndvRXJSS1liM1AKRnVON0d0WTZBckNGcXo4dyt4ZFZFYW1pblhpZnQ3b1J4bklhL0hZKzA1VXEvcml5MmROMzdEdUd4a01uZFJ2Nwp0Z3E0WG5QeXRwWjlpSVZBcXpVMXF0bDc2ZHdmVlhNeTUzaW9zOWppUkJ4SDdMV2NiRTdib1h6Yk1VWi9Da1NwCkhsVHVzczdKdENxaW81MjlhT0VXZHdLQmdEYWtCazJkWllOOVRZY2U1cG1NK1ZPdlVPalRtTEg2b0FxaG9mY2kKQzc2RWNLS2ZpTGJ3OWh1RU9tZ1Uzcjd2dWJJZEEvUWozTGVaaDVxbldUbVlkUXdVdm84aU52N2RaRE9CNjJHVQpqcjRjWTJzQmxSWG1ZVmNUK0hTSy9iZ3J1UjdrU2JtRDI0RCswOExMVW4vUFJQWEFxSzF6RVlvb0lpN2sreDNxClBRSXhBb0dBZUdiUlJjSlRwUXAzRmlMQ1E0VFpmeHAzUmUwalNXZTBScTFlUUpoekNySm1qRVZkbnArUzdYZUoKbnpaYVBOdGphWnFWbFVPN1k3a2RYay9jRThJTWFla2huR2h5cjFkL1J3L21GdDdySnBoekdYMlFPdTBCNzZNQQpEWUhRQTNrSVJoRmRDajF3MVkzalBPYVFqc2pUZ25CbUZLWDZYSENZYllkbDFKaXA2MkE9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==

我们再创建一个 prod 集群:

kind create cluster --name prod --wait 5m

再看 kubeconfig文件,可以看到两个context,两个cluster,两个user

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYR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ybTdBNFhIbGtoWXZnM3c4Q0F3RUFBYU5aTUZjd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZBOWlxWFRyYk43U1BQak84eGZtUmpiK3RPUm5NQlVHQTFVZEVRUU8KTUF5Q0NtdDFZbVZ5Ym1WMFpYTXdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSi9FdFpvZWE1TDVyTkEwemI0dAprSERZNjFPb2d3bTJUWXBpczJuTDNzcGttSnFTK3B1WnRqaUQwczhjUGZQSGdtKzhrblpyUzcwelErOGZwdXA3CmVyV3VxSmNvOVpDTXZxRHBTR3ljUWFOdDlkeERkdWVqU0JLZkNiaXRaSnRwa01QTGtXNHRmV1VSOTdTVmFJeFkKY0t3dGltWlBKVVZ6NUJMUTBJY0hzMWFBS0puN3lKaXloVWlpR1lRQ0h2d0hzUHBDMW94SEFMY3ZPeGZscGRlOAo4MzJ2dlpKNVRGbGdSVXRWUFRoSG45bmthWmhpYXBEOGljcURnUElCU2lZMTBkamd4eW1SbGlJS1JzckY0dHRjCmwwNWlISzIzQzZYQjlkU0tkUGhHeU1LaFROMDB1OEVWMktjREUybUFHRk1KUHZsTDFQVlo3WlJMMmdQV2NrV3AKNmFnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://127.0.0.1:46229
  name: kind-prod
contexts:
- context:
    cluster: kind-demo
    user: kind-demo
  name: kind-demo
- context:
    cluster: kind-prod
    user: kind-prod
  name: kind-prod
current-context: kind-prod
kind: Config
preferences: {}
users:
- name: kind-demo
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJSVd1TEZtRlFEY3N3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBM01UZ3hNak16TkROYUZ3MHl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和user

kubectl cluster-info --context kind-prod

删除集群

kind delete cluster --name prod
kubectl config use-context kind-demo # 将current-context设置为之前的demo集群

将docker镜像加载到cluster中

podman build -t rust_http_proxy .
podman tag rust_http_proxy:latest rust_http_proxy:1.0 # k8s的Kubernetes imagePullPolicy 不允许使用latest的镜像。所以给个版本标记
yum install -y docker # 安装podman的docker兼容层,用于下面的docker-image命令
kind load docker-image rust_http_proxy:1.0 --name demo
podman exec -it demo-control-plane crictl images # 查看集群中的镜像列表

集群中的镜像列表如下:

IMAGE                                      TAG                  IMAGE ID            SIZE
docker.io/arloor/rust_http_proxy           1.0                  540e623206d7e       22.2MB
docker.io/kindest/kindnetd                 v20230511-dc714da8   b0b1fa0f58c6e       27.7MB
docker.io/kindest/local-path-helper        v20230510-486859a6   be300acfc8622       3.05MB
docker.io/kindest/local-path-provisioner   v20230511-dc714da8   ce18e076e9d4b       19.4MB
localhost/rust_http_proxy                  1.0                  65631e7a5e1da       22.2MB
registry.k8s.io/coredns/coredns            v1.10.1              ead0a4a53df89       16.2MB
registry.k8s.io/etcd                       3.5.7-0              86b6af7dd652c       102MB
registry.k8s.io/kube-apiserver             v1.27.3              c604ff157f0cf       83.5MB
registry.k8s.io/kube-controller-manager    v1.27.3              9f8f3a9f3e8a9       74.4MB
registry.k8s.io/kube-proxy                 v1.27.3              9d5429f6d7697       72.7MB
registry.k8s.io/kube-scheduler             v1.27.3              205a4d549b94d       59.8MB
registry.k8s.io/pause                      3.7                  221177c6082a8       311kB

进入控制面看看

echo "podman exec -it demo-control-plane /bin/bash" > /usr/local/bin/pssh
chmod +x /usr/local/bin/pssh
pssh

设置下容器内的apt镜像 debian11

## 阿里云镜像
cat > /etc/apt/sources.list <<EOF
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
EOF
## 腾讯云内网镜像
cat > /etc/apt/sources.list << EOF
deb http://mirrors.tencentyun.com/debian/ bullseye main contrib non-free
deb-src http://mirrors.tencentyun.com/debian/ bullseye main contrib non-free
deb http://mirrors.tencentyun.com/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.tencentyun.com/debian/ bullseye-updates main contrib non-free
deb http://mirrors.tencentyun.com/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.tencentyun.com/debian/ bullseye-backports main contrib non-free
deb http://mirrors.tencentyun.com/debian-security/ bullseye-security main contrib non-free
deb-src http://mirrors.tencentyun.com/debian-security/ bullseye-security main contrib non-free
EOF
# 这些Http代理环境变量是从主机传递过来的,如果不想要的话
# 可以删除当前集群,然后清空http代理,重新闯将
cat >> ~/.bashrc <<EOF 
export https_proxy=
export http_proxy=
export HTTP_PROXY=
export HTTPS_PROXY=
EOF
apt update
apt install -y vim

创建工作负载

assign-pods-nodes

# 给控制面node增加label app=all
kubectl label nodes demo-control-plane app=all

# 加载镜像,并将镜像导入到集群
podman pulll docker.io/arloor/rust_http_proxy
podman tag docker.io/arloor/rust_http_proxy:latest rust_http_proxy:1.0
kind load docker-image rust_http_proxy:1.0 --name demo

## 独立启动pod
kubectl run proxy --image=localhost/rust_http_proxy:1.0
kubectl get pods --show-labels
kubectl delete pod proxy

## 通过deployment启动pod
cat > a.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: proxy-deployment
spec:
  replicas: 1 # tells deployment to run 2 pods matching the template
  selector:
    matchLabels:
      app: all
  template:
    metadata:
      labels:
        app: all
    spec:
      containers:
      - name: proxy
        image: localhost/rust_http_proxy:1.0
        ports:
        - containerPort: 3128
EOF
kubectl apply -f a.yaml # 新建一个deployment
kubectl get deployments --show-labels