首页 > 其他分享 >使用containerd作为容器运行时拉取镜像的方法

使用containerd作为容器运行时拉取镜像的方法

时间:2022-12-06 16:57:03浏览次数:36  
标签:name containerd system server metrics 时拉取 io 镜像 k8s

k8s v1.24版本后默认使用containerd作为容器运行时,很多镜像库使用的是gcr.io,国内可能无法成功拉取。接下来将通过搭建Metrics Server来演示该情况的解决方法。

components.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
    rbac.authorization.k8s.io/aggregate-to-admin: "true"
    rbac.authorization.k8s.io/aggregate-to-edit: "true"
    rbac.authorization.k8s.io/aggregate-to-view: "true"
  name: system:aggregated-metrics-reader
rules:
  - apiGroups:
      - metrics.k8s.io
    resources:
      - pods
      - nodes
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
rules:
  - apiGroups:
      - ""
    resources:
      - nodes/metrics
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - pods
      - nodes
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server-auth-reader
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
  - kind: ServiceAccount
    name: metrics-server
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server:system:auth-delegator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
  - kind: ServiceAccount
    name: metrics-server
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    k8s-app: metrics-server
  name: system:metrics-server
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:metrics-server
subjects:
  - kind: ServiceAccount
    name: metrics-server
    namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  ports:
    - name: https
      port: 443
      protocol: TCP
      targetPort: https
  selector:
    k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: metrics-server
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        k8s-app: metrics-server
    spec:
      containers:
        - args:
            - --kubelet-insecure-tls # access to kubelet
            - --cert-dir=/tmp
            - --secure-port=4443
            - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
            - --kubelet-use-node-status-port
            - --metric-resolution=15s

          image: k8s.gcr.io/metrics-server/metrics-server:v0.6.1
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /livez
              port: https
              scheme: HTTPS
            periodSeconds: 10
          name: metrics-server
          ports:
            - containerPort: 4443
              name: https
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /readyz
              port: https
              scheme: HTTPS
            initialDelaySeconds: 20
            periodSeconds: 10
          resources:
            requests:
              cpu: 100m
              memory: 200Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            runAsUser: 1000
          volumeMounts:
            - mountPath: /tmp
              name: tmp-dir
      nodeSelector:
        kubernetes.io/os: linux
      priorityClassName: system-cluster-critical
      serviceAccountName: metrics-server
      volumes:
        - emptyDir: {}
          name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  labels:
    k8s-app: metrics-server
  name: v1beta1.metrics.k8s.io
spec:
  group: metrics.k8s.io
  groupPriorityMinimum: 100
  insecureSkipTLSVerify: true
  service:
    name: metrics-server
    namespace: kube-system
  version: v1beta1
  versionPriority: 100

我们需要使用ctr或者crictl来代替docker命令,但是crictl是没有类似docker tag功能的。当我们使用ctr时需注意,ctr和k8s一样,都有命名空间的概念,默认是default,因此在操作时需要加上-n=k8s.io,这样k8s才会正确识别镜像。

setup.sh

#!/bin/bash
#

# https://github.com/kubernetes-sigs/metrics-server
# wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# sed '/args:/a\        - --kubelet-insecure-tls' components.yaml

# download and change yaml
# wget -O- https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml \
#   | sed '/args:/a\        - --kubelet-insecure-tls' - > components.yaml

# use ali registry to speed up
repo=registry.aliyuncs.com/google_containers

name=k8s.gcr.io/metrics-server/metrics-server:v0.6.1

# remove prefix
#src_name=${name#k8s.gcr.io/}
#src_name=${name#metrics-server/}
src_name=metrics-server:v0.6.1

ctr -n=k8s.io image pull $repo/$src_name

# rename to fit k8s
ctr -n=k8s.io image tag $repo/$src_name $name
ctr -n=k8s.io image rm $repo/$src_name

# add args: - --kubelet-insecure-tls
kubectl apply -f components.yaml

完成后我们可以查看Metrics Server的部署情况
在这里插入图片描述

标签:name,containerd,system,server,metrics,时拉取,io,镜像,k8s
From: https://www.cnblogs.com/LMFrank/p/16955781.html

相关文章

  • no space left on device 更换docker容器和镜像默认存储路径
    查看当前docker默认路径dockerinfo停止docker服务systemctlstopdocker修改docker服务启动文件vim/usr/lib/systemd/system/docker.service找到ExecStart=字......
  • openstack上传镜像到glance
    以qcow2模板为例1.上传镜像qcow2文件到服务器。2.先转换qcow2格式为raw,例如:qemu-imgconvert-fqcow2-Orawwin2012r2.qcow2win2012r2.raw3.再将raw镜像上传到gl......
  • docker镜像保存及导出(save,export)
    前言:有时自己的做好的docker镜像,想将这个docker容器弄到其他服务器上去运行;或者已经运行的容器,将其弄导出,运行到其他地方进行测试 1.查看要要保存的镜像的IDdocker i......
  • Docker镜像与容器的工作原理
    提纲1、bootfs和rootfs2、镜像层和镜像3、容器层和容器4、联合文件系统​1、bootfs和rootfs一般而言,Linux的操作系统由两类文件系统组成:bootfs(bootfilesystem)和r......
  • docker 镜像、容器的导入导出
    1.本地镜像的载入载出1.镜像载出tar包dockersavemysql:8>/root/mysql-8.tardockersavecd3ed0dfff7e-o/root/mysql-8.targzip包dockersavemysql:8|g......
  • 【最新】最全的Google镜像站地址
    写在前面遇到问题,有时光靠Baidu有时解决不了问题,所以需要求助Google,里面有好多国外网友的博客、StackoverFlow、GithubIssues、官方文档等等的大量一手英文资料,如果你想......
  • ceotos7 yum镜像源更换为阿里云
    1.安装wgetyuminstall-ywget2.备份原镜像mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.back3.下载阿里云镜像cd/etc/yum.repos.d......
  • 制作nodejs镜像
    DockerfileFROMubuntu:22.04#wgethttps://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.gz#wgethttps://github.com/yarnpkg/yarn/releases/download/v......
  • Linux更换镜像源
    UbuntuUbuntu打开并修改/etc/apt/sources.list文件即可通用源:debmirror://mirrors.ubuntu.com/mirrors.txtfocalmainrestricteduniversemultiversedeb-srcm......
  • 基于jenkins+kubernetes的cicd流程实践三:清除镜像定时任务
    6.定时清除历史镜像:万里长征的最后一步收尾工作,换一种更“原生”的玩法,找一找新感觉,手搓走起.....参考:https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/......