sh{
"registry-mirrors": ["https://npud8xro.mirror.aliyuncs.com"],
"insecure-registries":["harbor.zhang.org"],
"log-level": "debug"
}
shcat /etc/hosts
127.0.0.1 localhost
#127.0.1.1 zhang
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.0.0.206 harbor.zhang.org
10.0.0.200 kubeapi.zhang.org
sh#创建名称空间
kubectl create ns hello
#创建serviceaccount
kubectl create serviceaccount hello-admin -n hello
#查看创建结果
root@k8s-master1:~# kubectl get sa -n hello
NAME SECRETS AGE
default 0 23h
hello-admin 0 23h
#创建rolebinding绑定到serviceaccount
kubectl create rolebinding hello-admin --clusterrole=cluster-admin --serviceaccount hello:hello-admin -n hello
#创建pod
root@k8s-master1:/data/cicd-k8s# cat hello-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: test
namespace: hello
spec:
containers:
- image: ikubernetes/admin-box:v1.2
name: sleep
command: ["/bin/sh","-c","sleep 99999"]
serviceAccountName: hello-admin
#查看token信息
root@k8s-master1:/data/cicd-k8s# kubectl exec -it test -n hello -- /bin/sh
root@test # cat /var/run/secrets/kubernetes.io/serviceaccount/
..2024_06_19_02_22_36.3434471662/ ca.crt token
..data/ namespace
root@test # cat /var/run/secrets/kubernetes.io/serviceaccount/token
eyJhbGciOiJSUzI1NiIsImtpZCI6IktYSTRlVWdkb1M2M1BESkVBX2dDZmo1ZDVqcFBDNkZ5RFo0c1EyRWtJS0kifQ.eyJhdWQiOlsiYXBpIiwiaXN0aW8tY2EiXSwiZXhwIjoxNzUwMjk5NzU2LCJpYXQiOjE3MTg3NjM3NTYsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2YyIsImt1YmVybmV0ZXMuaW8iOnsibmFtZXNwYWNlIjoiaGVsbG8iLCJwb2QiOnsibmFtZSI6InRlc3QiLCJ1aWQiOiI1Yjg3NjU4ZS1mZWY4LTQ0NjYtYjVkNS1kY2Q4ZjYyMzI1NWYifSwic2VydmljZWFjY291bnQiOnsibmFtZSI6ImhlbGxvLWFkbWluIiwidWlkIjoiY2QwZTY3YjYtNDE0ZS00ZmI1LTliZTMtYTBlMzg1NjIwYmQzIn0sIndhcm5hZnRlciI6MTcxODc2NzM2M30sIm5iZiI6MTcxODc2Mzc1Niwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmhlbGxvOmhlbGxvLWFkbWluIn0.DheWLrHN2GzQx-y_qdIkg7APd3lI8M6h2r1wl48sz3fe79lkaTPqwQoxAEbIV4aN8K9DzQhle7LtBl9I6dBfR0-UiTUe44QXyF68cm43F8b5imcIRKkLF9HR7FOgz9IOdgsaC-hJoWQ2XPCBUZN8PnO_z9lDqN1uhgZ5ATMCMyrrJypIu-4_kqcmXxG9yCFt0aQOGsWg5I-wo53j071G5P157svn9nJcccw7TEJXWvHZk_v3EhK65_sW6KZO6fn75mG1RbH9Nuvfwfcno48ZPePVp75Ua3gJ9Kp-c2vLarDwpEMW8IX2Kw2UoCIMaHEtKQ-yDzenJ7ztuDIRO6ZAeQ
### 将这段token信息复制到刚才Jenkins要创建的全局凭据secret中即可
sh#我这里环境是1.24.13,
kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.13", GitCommit:"49433308be5b958856b6949df02b716e0a7cf0a3", GitTreeState:"clean", BuildDate:"2023-04-12T12:15:50Z", GoVersion:"go1.19.8", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.13", GitCommit:"49433308be5b958856b6949df02b716e0a7cf0a3", GitTreeState:"clean", BuildDate:"2023-04-12T12:08:36Z", GoVersion:"go1.19.8", Compiler:"gc", Platform:"linux/amd64"}
本文作者:笑一个吧~
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 本文为博主「笑一个吧~」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 许可协议。转载请注明出处!