官方镜像

简要概述

这里说明所用到 k8s 官方镜像与相关的组件地址。

当在部署时,可以从外部获取依赖文件至以下路径:

ansible/roles/binary/files

控制平面

kubeadm config images list --kubernetes-version stable-1.22
kubeadm config images list --kubernetes-version stable-1.26
https://cdn.dl.k8s.io/release/stable-1.26.txt

k8s 1.26 版本

registry.k8s.io/kube-apiserver:v1.26.11
registry.k8s.io/kube-controller-manager:v1.26.11
registry.k8s.io/kube-scheduler:v1.26.11
registry.k8s.io/kube-proxy:v1.26.11
registry.k8s.io/pause:3.9
registry.k8s.io/etcd:3.5.9-0
registry.k8s.io/coredns/coredns:v1.9.3

k8s 1.22 版本

k8s.gcr.io/kube-apiserver:v1.22.6
k8s.gcr.io/kube-controller-manager:v1.22.6
k8s.gcr.io/kube-scheduler:v1.22.6
k8s.gcr.io/kube-proxy:v1.22.6
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4

基本术语

变量 取值范围 说明
KUBE_VERSION 见版本历史 安装k8s的版本,默认获取根目录下"version"文件内容
KUBERNETES_SERVER_ARCH [amd64, arm, arm64, ppc64le, s390x] 服务端cpu架构,默认为amd64
KUBERNETES_CLIENT_OS [linux, darwin, windows] 客户端的操作系统类型,默认为当前系统类型
KUBERNETES_CLIENT_ARCH [amd64, arm, arm64, ppc64le, s390x, windows] 客户的cpu架构,默认为当前系统类型
KUBERNETES_SKIP_CONFIRM 任意值 如果存在该变量,下载则无需确认
KUBERNETES_RELEASE_URL [https://dl.k8s.io] 下载的地址,格式如下
KUBERNETES_DOWNLOAD_TESTS 任意值 如果存在该变量,则下载测试用例

KUBERNETES_RELEASE_URL地址格式:

${KUBERNETES_RELEASE_URL}/${KUBE_VERSION}/kubernetes-server-${KUBERNETES_CLIENT_OS}-${KUBERNETES_SERVER_ARCH}.tar.gz
${KUBERNETES_RELEASE_URL}/${KUBE_VERSION}/kubernetes-client-${KUBERNETES_CLIENT_OS}-${KUBERNETES_SERVER_ARCH}.tar.gz

Kubernetes镜像

下载Releasing包

https://github.com/kubernetes/kubernetes/releases

选择需要的版本,展开"Assets":

名称 说明
Kubernetes Source Code 编译后的结果
Source code (zip) 源代码zip压缩打包
Source code (tar.gz) 源代码以tar.gz压缩打包

点击下载 “Kubernetes Source Code” 获得文件 “kubernetes.tar.gz",通过SHA256验证后,则解压至目录 “ansible/roles/binary/files” 里。

SHA256计算方式:

shasum -a 256 kubernetes.tar.gz
https://github.com/kubernetes/kubernetes/tree/master/build#releasing

获取二进制文件

cd kubernetes

export KUBERNETES_SERVER_ARCH=amd64
export KUBERNETES_CLIENT_OS=linux
export KUBERNETES_CLIENT_ARCH=amd64
export KUBERNETES_SKIP_CONFIRM=true
export KUBERNETES_RELEASE_URL=https://dl.k8s.io
export KUBERNETES_DOWNLOAD_TESTS=true

./cluster/get-kube-binaries.sh

以上几个变量说明:

https://dl.k8s.io/v1.22.6/kubernetes-server-linux-amd64.tar.gz
https://dl.k8s.io/v1.22.6/kubernetes-client-linux-amd64.tar.gz

# 以下为设置了 KUBERNETES_DOWNLOAD_TESTS 变量才做下载
https://dl.k8s.io/v1.22.6/kubernetes-test-portable.tar.gz
https://dl.k8s.io/v1.22.6/kubernetes-test-linux-amd64.tar.gz
server/kubernetes-server-linux-amd64.tar.gz
client/kubernetes-client-linux-amd64.tar.gz

# 以下为设置了 KUBERNETES_DOWNLOAD_TESTS 变量才做下载
test/kubernetes-test-linux-amd64.tar.gz
test/kubernetes-test-portable.tar.gz

解压各压缩包

cd ..

tar xzvf kubernetes/server/kubernetes-server-linux-amd64.tar.gz
tar xzvf kubernetes/client/kubernetes-client-linux-amd64.tar.gz

# 以下为设置了 KUBERNETES_DOWNLOAD_TESTS 变量才做下载
tar xzvf kubernetes/test/kubernetes-test-linux-amd64.tar.gz
tar xzvf kubernetes/test/kubernetes-test-portable.tar.gz

导入容器镜像

export KUBE_VERSION=v1.22.6
export INTERNAL_IMAGES_NAMESPACE=registry.cn-hangzhou.aliyuncs.com/kube-image-repo

cd kubernetes/server/bin

for img in kube-apiserver kube-controller-manager kube-proxy kube-scheduler
do
    #docker import ${img}.tar ${INTERNAL_IMAGES_NAMESPACE}/${img}:${KUBE_VERSION}
    docker load -i ${img}.tar

    img_id=$(docker images | grep k8s.gcr.io/${img} | grep ${KUBE_VERSION} | awk '{ print $3 }')
    docker tag ${img_id} ${INTERNAL_IMAGES_NAMESPACE}/${img}:${KUBE_VERSION}

    docker push ${INTERNAL_IMAGES_NAMESPACE}/${img}:${KUBE_VERSION}
done

注意:这里必须使用docker load,而不是docker import

pause镜像

https://github.com/kubernetes/kubernetes/tree/master/build/pause

etcd镜像

# 下载代码
git clone https://github.com/etcd-io/etcd.git

# 切换指定版本
git checkout $tag

# 编译linux amd64版本
ARCH=amd64 GOOS=linux make build

# 打包容器镜像
cd bin
cp ../Dockerfile-release.amd64 Dockerfile
docker build -f Dockerfile ./ -t registry.cn-hangzhou.aliyuncs.com/kube-image-repo/etcd:3.5.1

coredns镜像

https://github.com/coredns/coredns

cni-plugins

https://github.com/containernetworking/plugins/releases

https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-amd64-v1.0.1.tgz

cri-tools

VERSION="v1.23.0"
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz
VERSION="v1.23.0"
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/critest-$VERSION-linux-amd64.tar.gz
sudo tar zxvf critest-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f critest-$VERSION-linux-amd64.tar.gz

containerd

https://github.com/containerd/containerd/releases

calico

https://github.com/projectcalico/calico/releases

flanneld

https://github.com/flannel-io/flannel/releases