Kubernete 本地 開發/調試環境 minikube microk8s kubeadm拉取 k8s.gcr.io 問題

廢話不說,linux下使用如下腳本,保證可以下載相關鏡像

腳本非原創,主要是作者原來的阿里雲鏡像庫改爲了微軟Azure源
,其原理是調用的是微軟Azure的源去下載的相關docker鏡像,然後通過tag改名爲本地鏡像.版本號根據具體按照情況,可以改變

#!/bin/bash

set -e

# Check version in https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/
# Search "Running kubeadm without an internet connection"
# For running kubeadm without an internet connection you have to pre-pull the required master images for the version of choice:
KUBE_VERSION=v1.13.2
KUBE_PAUSE_VERSION=3.1
ETCD_VERSION=3.2.24
DNS_VERSION=1.14.8
CORE_DNS_VERSION=1.2.6

GCR_URL=k8s.gcr.io
ALIYUN_URL=gcr.azk8s.cn/google_containers

images=(kube-proxy-amd64:${KUBE_VERSION}
kube-proxy:${KUBE_VERSION}
kube-scheduler-amd64:${KUBE_VERSION}
kube-scheduler:${KUBE_VERSION}
kube-controller-manager-amd64:${KUBE_VERSION}
kube-controller-manager:${KUBE_VERSION}
kube-apiserver-amd64:${KUBE_VERSION}
kube-apiserver:${KUBE_VERSION}
pause-amd64:${KUBE_PAUSE_VERSION}
pause:${KUBE_PAUSE_VERSION}
etcd-amd64:${ETCD_VERSION}
etcd:${ETCD_VERSION}
k8s-dns-sidecar-amd64:${DNS_VERSION}
k8s-dns-kube-dns-amd64:${DNS_VERSION}
coredns:${CORE_DNS_VERSION}
k8s-dns-dnsmasq-nanny-amd64:${DNS_VERSION})


for imageName in ${images[@]} ; do
	  docker pull $ALIYUN_URL/$imageName
	    docker tag  $ALIYUN_URL/$imageName $GCR_URL/$imageName
	      docker rmi $ALIYUN_URL/$imageName
      done
docker images



執行完畢效果如圖


REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-controller-manager-amd64   v1.13.2             b9027a78d94c        3 months ago        146MB
k8s.gcr.io/kube-controller-manager         v1.13.2             b9027a78d94c        3 months ago        146MB
k8s.gcr.io/kube-apiserver-amd64            v1.13.2             177db4b8e93a        3 months ago        181MB
k8s.gcr.io/kube-apiserver                  v1.13.2             177db4b8e93a        3 months ago        181MB
k8s.gcr.io/kube-proxy-amd64                v1.13.2             01cfa56edcfc        3 months ago        80.3MB
k8s.gcr.io/kube-proxy                      v1.13.2             01cfa56edcfc        3 months ago        80.3MB
k8s.gcr.io/kube-scheduler-amd64            v1.13.2             3193be46e0b3        3 months ago        79.6MB
k8s.gcr.io/kube-scheduler                  v1.13.2             3193be46e0b3        3 months ago        79.6MB
k8s.gcr.io/coredns                         1.2.6               f59dcacceff4        5 months ago        40MB
k8s.gcr.io/kube-proxy                      v1.12.1             61afff57f010        6 months ago        96.6MB
k8s.gcr.io/kube-proxy-amd64                v1.12.1             61afff57f010        6 months ago        96.6MB
k8s.gcr.io/kube-scheduler-amd64            v1.12.1             d773ad20fd80        6 months ago        58.3MB
k8s.gcr.io/kube-scheduler                  v1.12.1             d773ad20fd80        6 months ago        58.3MB
k8s.gcr.io/kube-apiserver-amd64            v1.12.1             dcb029b5e3ad        6 months ago        194MB
k8s.gcr.io/kube-apiserver                  v1.12.1             dcb029b5e3ad        6 months ago        194MB
k8s.gcr.io/kube-controller-manager-amd64   v1.12.1             aa2dd57c7329        6 months ago        164MB
k8s.gcr.io/kube-controller-manager         v1.12.1             aa2dd57c7329        6 months ago        164MB
k8s.gcr.io/etcd-amd64                      3.2.24              3cab8e1b9802        7 months ago        220MB
k8s.gcr.io/etcd                            3.2.24              3cab8e1b9802        7 months ago        220MB
k8s.gcr.io/etcd-amd64                      3.2.18              b8df3b177be2        12 months ago       219MB
k8s.gcr.io/etcd                            3.2.18              b8df3b177be2        12 months ago       219MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64     1.14.8              c2ce1ffb51ed        15 months ago       41MB
k8s.gcr.io/k8s-dns-sidecar-amd64           1.14.8              6f7f2dc7fab5        15 months ago       42.2MB
k8s.gcr.io/k8s-dns-kube-dns-amd64          1.14.8              80cc5ea4b547        15 months ago       50.5MB
k8s.gcr.io/pause-amd64                     3.1                 da86e6ba6ca1        16 months ago       742kB
k8s.gcr.io/pause                           3.1                 da86e6ba6ca1        16 months ago       742kB


Dashboard https://github.com/kubernetes/dashboard/releases 目前暫時不支持1.13.x

以下安裝dashboard的yaml腳本只支持到1.12,鏡像已經替換爲阿里雲,可以放心直接使用.使用命令kubectl apply -f x.yaml

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ------------------- Dashboard Secret ------------------- #

apiVersion: v1
kind: Secret
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard-certs
  namespace: kube-system
type: Opaque

---
# ------------------- Dashboard Service Account ------------------- #

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system

---
# ------------------- Dashboard Role & Role Binding ------------------- #

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: kubernetes-dashboard-minimal
  namespace: kube-system
rules:
  # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["create"]
  # Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["create"]
  # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
  verbs: ["get", "update", "delete"]
  # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
  resources: ["configmaps"]
  resourceNames: ["kubernetes-dashboard-settings"]
  verbs: ["get", "update"]
  # Allow Dashboard to get metrics from heapster.
- apiGroups: [""]
  resources: ["services"]
  resourceNames: ["heapster"]
  verbs: ["proxy"]
- apiGroups: [""]
  resources: ["services/proxy"]
  resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
  verbs: ["get"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: kubernetes-dashboard-minimal
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: kubernetes-dashboard-minimal
subjects:
- kind: ServiceAccount
  name: kubernetes-dashboard
  namespace: kube-system

---
# ------------------- Dashboard Deployment ------------------- #

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: registry.cn-hangzhou.aliyuncs.com/kuberneters/kubernetes-dashboard-amd64:v1.10.1
        ports:
        - containerPort: 8443
          protocol: TCP
        args:
          - --auto-generate-certificates
          # Uncomment the following line to manually specify Kubernetes API server Host
          # If not specified, Dashboard will attempt to auto discover the API server and connect
          # to it. Uncomment only if the default does not work.
          # - --apiserver-host=http://my-address:port
        volumeMounts:
        - name: kubernetes-dashboard-certs
          mountPath: /certs
          # Create on-disk volume to store exec logs
        - mountPath: /tmp
          name: tmp-volume
        livenessProbe:
          httpGet:
            scheme: HTTPS
            path: /
            port: 8443
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      - name: kubernetes-dashboard-certs
        secret:
          secretName: kubernetes-dashboard-certs
      - name: tmp-volume
        emptyDir: {}
      serviceAccountName: kubernetes-dashboard
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule

---
# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章