其他分享
首页 > 其他分享> > kubadm方式安装k8s时的images安装和init操作

kubadm方式安装k8s时的images安装和init操作

作者:互联网

    使用kubeadm安装k8s时,有一步骤时下载images操作,一般度很多使用的方法是:使用docker images下载镜像再次tag镜像的名称,然后初始化的时候在配置集群子ip信息等

如下:

        1.设置kubelet国内的pause镜像
        cat >/etc/sysconfig/kubelet<<EOF
        KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.1"
        EOF
        
        2.Kubeadm初始化
        # 初始化时报错提示没有镜像文件,需要先下载在初始化(下面脚本只适用1.15.3版本)
        name=(kube-apiserver:v1.15.3空格kube-controller-manager:v1.15.3空格kube-scheduler:v1.15.3空格kube-proxy:v1.15.3空格pause:3.1空格etcd:3.3.10 coredns:1.3.1)
        # 修改镜像的名称
        for info in ${name[@]}
        do
        docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$info
        docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$info   k8s.gcr.io/$info
        docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$info
        Done
        
        #初始化master 
        #kubectl --version#查看版本
        #kubeadm init --kubernetes-version=v1.15.3 --pod-network-cidr=10.1.0.0/16 #--apiserver-advertise-address=192.168.191.11 --ignore-preflight-errors=Swap

   在此给大家介绍一个简单的方法

        #在获得vip的master节点上生成创始化配置文件 

        kubeadm config print init-defaults > kubeadm-init.yaml  #必须是yaml格式的文件

            apiVersion: kubeadm.k8s.io/v1beta2
            bootstrapTokens:
            - groups:
              - system:bootstrappers:kubeadm:default-node-token
              token: abcdef.0123456789abcdef
              ttl: 24h0m0s
              usages:
              - signing
              - authentication
            kind: InitConfiguration
            localAPIEndpoint:
              advertiseAddress: 192.168.191.30     #本机ip
              bindPort: 6443
            nodeRegistration:
              criSocket: /var/run/dockershim.sock
              name: k8s-3
              taints:
              - effect: NoSchedule
                key: node-role.kubernetes.io/master
            ---
            apiServer:
              timeoutForControlPlane: 4m0s
            apiVersion: kubeadm.k8s.io/v1beta2
            certificatesDir: /etc/kubernetes/pki
            clusterName: kubernetes
            controlPlaneENDPOINT: "192.168.191.30:58443"      #此项如没有请自行添加,此处请填写你的高可用的VIP地址及端口
            controllerManager: {}
            dns:
              type: CoreDNS
            etcd:
              local:
                dataDir: /var/lib/etcd
            imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers   #国内阿里的k8s镜像元
            kind: ClusterConfiguration
            kubernetesVersion: v1.17.4                            # 镜像的版本
            networking:
              dnsDomain: cluster.local
              podSubnet: 10.244.0.0/16                          # pod的网段,没有该设置,需要添加
              serviceSubnet: 10.96.0.0/12
            scheduler: {}
            ---  
            #使用ipvs  ,需要自己安装ipvsadm
            apiVersion: kubeproxy.config.k8s.io/v1alpha1
            kind: KubeProxyConfiguration
            featureGates:
              SupportIPVSProxyMode: true
            mode: ipvs

        #查看需要的镜像   

[root@k8s-3 ~]# kubeadm config images list 
W0323 17:27:46.000689   63185 validation.go:28] Cannot validate kube-proxy config - no validator is available   # 忽略
W0323 17:27:46.001023   63185 validation.go:28] Cannot validate kubelet config - no validator is available
k8s.gcr.io/kube-apiserver:v1.17.4
k8s.gcr.io/kube-controller-manager:v1.17.4
k8s.gcr.io/kube-scheduler:v1.17.4
k8s.gcr.io/kube-proxy:v1.17.4
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.5

        #拉取需要的镜像

        kubeadm config images pull --config kubeadm-init.yaml

        #初始化

        kubeadm init  --config kubeadm-init.yaml


标签:config,init,gcr,kubadm,io,kubeadm,k8s,安装
来源: https://blog.51cto.com/12182612/2481084