kubeadm 默認鏡像配置問題引伸

背景:node

每次使用功能kubeadm的時候都須要提早準備好鏡像,爲何自定義使用的鏡像源呢?
 docker

在沒有翻越圍牆時bootstrap

kubeadm init --kubernetes-version=v1.13.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.146.10

	[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-apiserver:v1.13.0: output: Trying to pull repository k8s.gcr.io/kube-apiserver ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 108.177.97.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-controller-manager:v1.13.0: output: Trying to pull repository k8s.gcr.io/kube-controller-manager ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 108.177.97.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-scheduler:v1.13.0: output: Trying to pull repository k8s.gcr.io/kube-scheduler ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 74.125.204.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-proxy:v1.13.0: output: Trying to pull repository k8s.gcr.io/kube-proxy ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 108.177.97.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/pause:3.1: output: Trying to pull repository k8s.gcr.io/pause ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 108.177.97.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/etcd:3.2.24: output: Trying to pull repository k8s.gcr.io/etcd ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 74.125.204.82:443: getsockopt: connection refused
, error: exit status 1
	[ERROR ImagePull]: failed to pull image k8s.gcr.io/coredns:1.2.6: output: Trying to pull repository k8s.gcr.io/coredns ... 
Get https://k8s.gcr.io/v1/_ping: dial tcp 108.177.125.82:443: getsockopt: connection refused
, error: exit status 1

去官網翻翻資料,看下是否能夠直接配置api

https://kubernetes.io/zh/docs/setup/independent/create-cluster-kubeadm/bash

 

使用kubeadm images list 能夠查看到kubeadm默認使用的鏡像列表app

一樣咱們是否是能夠改變kubeadm使用的默認鏡像呢?tcp

 首先咱們先看一下kubeadm命令ide

#讓咱們看下config選項
[root@K8s-master ~]# kubeadm config -h

There is a ConfigMap in the kube-system namespace called "kubeadm-config" that kubeadm uses to store internal configuration about the
cluster. kubeadm CLI v1.8.0+ automatically creates this ConfigMap with the config used with 'kubeadm init', but if you
initialized your cluster using kubeadm v1.7.x or lower, you must use the 'config upload' command to create this
ConfigMap. This is required so that 'kubeadm upgrade' can configure your upgraded cluster correctly.

Usage:
  kubeadm config [flags]
  kubeadm config [command]

Available Commands:
  images        Interact with container images used by kubeadm.
  migrate       Read an older version of the kubeadm configuration API types from a file, and output the similar config object for the newer version.
  print         Print configuration
  upload        Upload configuration about the current state, so that 'kubeadm upgrade' can later know how to configure the upgraded cluster.
  view          View the kubeadm configuration stored inside the cluster.

Flags:
  -h, --help                help for config
      --kubeconfig string   The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations are searched for an existing KubeConfig file. (default "/etc/kubernetes/admin.conf")

Global Flags:
      --log-file string   If non-empty, use this log file
      --rootfs string     [EXPERIMENTAL] The path to the 'real' host root filesystem.
      --skip-headers      If true, avoid header prefixes in the log messages
  -v, --v Level           log level for V logs

Use "kubeadm config [command] --help" for more information about a command.

images 查看kubeadm使用的鏡像網站

print 打印配置ui

由於我須要更改的是kubeadm使用的鏡像因此繼續使用kuberadm config images -h 查看幫助

[root@K8s-master ~]# kubeadm config images -h
Interact with container images used by kubeadm.

Usage:
  kubeadm config images [flags]
  kubeadm config images [command]

Available Commands:
  list        Print a list of images kubeadm will use. The configuration file is used in case any images or image repositories are customized.
  pull        Pull images used by kubeadm.

Flags:
  -h, --help   help for images

Global Flags:
      --kubeconfig string   The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations are searched for an existing KubeConfig file. (default "/etc/kubernetes/admin.conf")
      --log-file string     If non-empty, use this log file
      --rootfs string       [EXPERIMENTAL] The path to the 'real' host root filesystem.
      --skip-headers        If true, avoid header prefixes in the log messages
  -v, --v Level             log level for V logs

Use "kubeadm config images [command] --help" for more information about a command.

發現這裏只有一個list 和pull了能夠判斷查看配置能夠直接用 kubeadm config print

#先嚐試打印出配置文件
[root@K8s-master ~]# kubeadm config print 
Error: missing subcommand; "print" is not meant to be run on its own
Usage:
  kubeadm config print [flags]
  kubeadm config print [command]

Available Commands:
  init-defaults Print default init configuration, that can be used for 'kubeadm init'
  join-defaults Print default join configuration, that can be used for 'kubeadm join'

Flags:
  -h, --help   help for print

Global Flags:
      --kubeconfig string   The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations are searched for an existing KubeConfig file. (default "/etc/kubernetes/admin.conf")
      --log-file string     If non-empty, use this log file
      --rootfs string       [EXPERIMENTAL] The path to the 'real' host root filesystem.
      --skip-headers        If true, avoid header prefixes in the log messages
  -v, --v Level             log level for V logs

Use "kubeadm config print [command] --help" for more information about a command.

error: missing subcommand; "print" is not meant to be run on its own

#發現報錯,根據提示咱們是須要打印init-defaults init的默認配置文件
[root@K8s-master ~]# kubeadm config print init-defaults
apiVersion: kubeadm.k8s.io/v1beta1
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 1.2.3.4
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: k8s-master
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta1
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: ""
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.13.0
networking:
  dnsDomain: cluster.local
  podSubnet: ""
  serviceSubnet: 10.96.0.0/12
scheduler: {}

yaml格式的配置文件,

能夠看到這裏的默認image倉庫使用的是k8s.gcr.io

imageRepository: k8s.gcr.io

此時咱們把打印的配置文件copy到一個文件中new.yaml

把其中的imageRepository:改爲咱們的倉庫 如 mirrorgooglecontainers

在使用kubeadm config images list --config ./new.yaml

[root@K8s-master ~]# kubeadm config images list --config new.yaml 
W0116 10:29:05.964789  100887 common.go:86] WARNING: Detected resource kinds that may not apply: [InitConfiguration JoinConfiguration]
[config] WARNING: Ignored YAML document with GroupVersionKind kubeadm.k8s.io/v1beta1, Kind=JoinConfiguration
mirrorgooglecontainers/kube-apiserver:v1.13.0
mirrorgooglecontainers/kube-controller-manager:v1.13.0
mirrorgooglecontainers/kube-scheduler:v1.13.0
mirrorgooglecontainers/kube-proxy:v1.13.0
mirrorgooglecontainers/pause:3.1
mirrorgooglecontainers/etcd:3.2.24
mirrorgooglecontainers/coredns:1.2.6

能夠看到此時使用的鏡像已經改過來了

 

可是問題又來了,mirrorgooglecontainers並無因此的組件鏡像。。

能夠替換一個有因此組件的鏡像源網站,

 

亦或者在咱們先前看到的yaml文件中定義,可是礙於剛上手k8s這個實在沒有辦法自定義這個yaml文件。

但不妨這也是一個解決路徑。

 

先留着

相關文章
相關標籤/搜索