K8s registry secret:修订间差异
来自三线的随记
(创建页面,内容为“* 与 yaml -> imagePullSecrets相关 * 生成 docker-registry secret [root@d-jkpakzapp01 ~]# kubectl create secret --help Create a secret using specified subcomma…”) |
小无编辑摘要 |
||
第74行: | 第74行: | ||
Two ways to use:<blockquote>1. "为kubernetes.api" 创建一个用户 :</blockquote><blockquote>kind:ServiceAccount -> kubectl create -f </blockquote><blockquote>kubectl get serviceaccount **** -o yaml -> "查看用户信息"</blockquote><blockquote>"token可通过 kubectl get secret build-robot-secret -o yaml 获取(或通过describe命令获取)"[不知道有嘛用,先记录着吧]</blockquote><blockquote>"接下来我们将之前的"myregistrykey" 加入build-robot用户,让之后在使用此账户时,可pull私有仓库的加密资源"</blockquote><blockquote>kubectl get serviceaccounts build-robot -o yaml > ./ro.yaml</blockquote><blockquote>edit...</blockquote><blockquote>kubectl replace serviceaccount default -f ./ro.yaml</blockquote><blockquote>2.</blockquote><blockquote>在pod的yaml文件中,spec.imagepullsecrets下,添加- name: myregistrykey来忽略账户自带的key,直接pull自己私有仓库的项目</blockquote> | Two ways to use:<blockquote>1. "为kubernetes.api" 创建一个用户 :</blockquote><blockquote>kind:ServiceAccount -> kubectl create -f </blockquote><blockquote>kubectl get serviceaccount **** -o yaml -> "查看用户信息"</blockquote><blockquote>"token可通过 kubectl get secret build-robot-secret -o yaml 获取(或通过describe命令获取)"[不知道有嘛用,先记录着吧]</blockquote><blockquote>"接下来我们将之前的"myregistrykey" 加入build-robot用户,让之后在使用此账户时,可pull私有仓库的加密资源"</blockquote><blockquote>kubectl get serviceaccounts build-robot -o yaml > ./ro.yaml</blockquote><blockquote>edit...</blockquote><blockquote>kubectl replace serviceaccount default -f ./ro.yaml</blockquote><blockquote>2.</blockquote><blockquote>在pod的yaml文件中,spec.imagepullsecrets下,添加- name: myregistrykey来忽略账户自带的key,直接pull自己私有仓库的项目</blockquote> | ||
[[category:k8s]] |
2019年11月13日 (三) 10:02的最新版本
- 与 yaml -> imagePullSecrets相关
- 生成 docker-registry secret
[root@d-jkpakzapp01 ~]# kubectl create secret --help Create a secret using specified subcommand. Available Commands: docker-registry Create a secret for use with a Docker registry generic Create a secret from a local file, directory or literal value tls Create a TLS secret Usage: kubectl create secret [flags] [options] Use "kubectl <command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).
kubectl create secret docker-registry --help Create a new secret for use with Docker registries. Dockercfg secrets are used to authenticate against Docker registries. When using the Docker command line to push images, you can authenticate to a given registry by running: '$ docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'. That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to authenticate to the registry. The email address is optional. When creating applications, you may have a Docker registry that requires authentication. In order for the nodes to pull images on your behalf, they have to have the credentials. You can provide this information by creating a dockercfg secret and attaching it to your service account. Examples: # If you don't already have a .dockercfg file, you can create a dockercfg secret directly by using: kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL Options: --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. --append-hash=false: Append a hash of the secret to its name. --docker-email='': Email for Docker registry --docker-password='': Password for Docker registry authentication --docker-server='https://index.docker.io/v1/': Server location for Docker registry --docker-username='': Username for Docker registry authentication --dry-run=false: If true, only print the object that would be sent, without sending it. --from-file=[]: Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key. --generator='secret-for-docker-registry/v1': The name of the API generator to use. -o, --output='': Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file. --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --validate=true: If true, use a schema to validate the input before sending it Usage: kubectl create secret docker-registry NAME --docker-username=user --docker-password=password --docker-email=email [--docker-server=string] [--from-literal=key1=value1] [--dry-run] [options] Use "kubectl options" for a list of global command-line options (applies to all commands).
So :
kubectl create secret docker-registry myregistrykey --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL
and then:
转换标准输出:kubectl get secret myregistrykey --output="jsonpath={.data.\.dockerconfigjson}" | base64 -d
Check: :
kubectl get secrets myregistrykey
Two ways to use:
1. "为kubernetes.api" 创建一个用户 :
kind:ServiceAccount -> kubectl create -f
kubectl get serviceaccount **** -o yaml -> "查看用户信息"
"token可通过 kubectl get secret build-robot-secret -o yaml 获取(或通过describe命令获取)"[不知道有嘛用,先记录着吧]
"接下来我们将之前的"myregistrykey" 加入build-robot用户,让之后在使用此账户时,可pull私有仓库的加密资源"
kubectl get serviceaccounts build-robot -o yaml > ./ro.yaml
edit...
kubectl replace serviceaccount default -f ./ro.yaml
2.
在pod的yaml文件中,spec.imagepullsecrets下,添加- name: myregistrykey来忽略账户自带的key,直接pull自己私有仓库的项目