k8s使用

len连接集群报错

E1223 11:39:11.158869 4684 proxy_server.go:147] 
Error while proxying request: x509: certificate signed by unknown authority

解决方法:~/.kube/config 中添加 insecure-skip-tls-verify: true

apiVersion: v1
kind: Config
clusters:
- name: "local"
  cluster:
    insecure-skip-tls-verify: true
    server: "https://xxxx.xxxx.xxxx.xxxx:8443"

users:
- name: "local"
  user:
    token: "kubeconfig-user-6p6nmczk2l:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


contexts:
- name: "local"
  context:
    user: "local"
    cluster: "local"

current-context: "local"

硬件架构不兼容报错

错误信息:standard_init_linux.go:219: exec user process caused: exec format error

原因

  1. 硬件架构不兼容,arm、amd架构下编译的镜像可能不互通
    解决:针对不同架构创建不同的镜像,或创建跨架构的镜像
  2. shell执行不兼容,基于 bash 写的脚本在不同的 shell 解释器存在不兼容的情况,甚至有些 Linux 发行版没有 bash,或者默认的 shell 解释器不是 bash
    解决:脚本前指定所需的解释器,#!/bin/bash
  3. 脚本换行符,windows下换行符与类*Unix的不同
    解决:CRLF 替换为 LF

创建指定架构的镜像

# 无法跨平台的语言的编译时,需要在Dockerfile中指定交叉编译,如GoLang语言arm64架构:
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-w -s" -o

# build时指定平台
docker build --platform linux/amd64 -t xxhub/xxx/xxx:v1 ./

注:docker buildx 单个平台上实现跨CPU架构的镜像编译

拉取指定架构的镜像

  1. 先修改docker服务加参数 –experimental=true
  2. 拉取的时候指定平台参数,如用docker pull –platform arm64 xxhub/xxx:v1
  3. 用 docker inspect xxhub/xxx:v1 查看镜像是否指定平台架构的

上传本地镜像到镜像库

# 拉取arm64的镜像
docker pull --platform arm64 chaifeng/mycli:1.26
# 查看镜像库架构
docker inspect chaifeng/mycli:1.26
# 设置镜像库
docker tag chaifeng/mycli:1.26 xxxhub.xxxx.com/tech/mycli:1.26
# 上传到镜像库
docker push xxxhub.xxxx.com/tech/mycli:1.26

镜像加速

MAC:任务栏点击 Docker Desktop -> Perferences,在左侧导航菜单选择 Docker Engine,在右侧像下边一样编辑 json 文件,修改完成之后,点击 Apply & Restart 按钮

{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}

检查加速器是否生效

# 执行 $ docker info,如果从结果中看到了如下内容,说明配置成功。
Registry Mirrors:
 https://hub-mirror.c.163.com/

参考:https://yeasy.gitbook.io/docker_practice/install/mirror

This entry was posted in 小技巧. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.