Create Secret
- Get information :
username : the name of your deploy token
password : the value of token
email: your email
auth : base 64 username:password
you can generate auth with this command
echo "patoken:npAdzEy79ybtQdfdf" | base64
Result : gHy5cm9sbGZyb250ZW5kdG9rZW46bnBBZHpFeTc5eWJ0UWtoaEtUaG0Y
- Create a yaml file 'registry-front-credentials.yml' with your informations
{
"auths": {
"https://registry.gitlab.com":{
"username":"patoken",
"password":"npAdYiy79ybtQdfdf",
"email":"your@gmail.com",
"auth":"gHy5cm9sbGZyb250ZW5kdG9rZW46bnBBZHpFeTc5eWJ0UWtoaEtUaG0Y"
}
}
}
- Encode with base64 the file above with this command
base64 registry-front-credentials.yml > output.txt
Result : vi output.txt
rwogICAgImF1dGhzIjogewogYCAgICAgICJodHRwczovL3JlZ2lzdHJ5LmdpdGxhYi5jb20iOnsK
ICAgICAgICAgICAgInVzZXJuYW1lIjoicGF5cm9sbGZyb250ZW5kdG9rZW4iLAogICAgICAgICAg
ICAicGFzc3dvcmQiOiJucEFlekV5Nzl5YnRRa2hoS1RobSIsCiAgICAgICAgICAgICJlbWFpbCI6
InZpeGF3ZWJAZ21haWwuY29tIiwKICAgICAgICAgICAgImF1dGgiOiJjR0Y1Y205c2JHWnliMjUw
Wlc1a2RHOXJaVzQ2Ym5CQlpIcEZlVGM1ZVdKMFVXdG9hRXRVYUcwSyIKICAgICAgICB9CiAgICB9
GuYt
- Create the secret with Yaml file. Be attention the token in dockerconfigjson should be in one line
apiVersion: v1
kind: Secret
metadata:
name: registryfront-credentials
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: rwogICAgImF1dGhzIjogewogYCAgICAgICJodHRwczovL3JlZ2lzdHJ5LmdpdGxhYi5jb20iOnsK
ICAgICAgICAgICAgInVzZXJuYW1lIjoicGF5cm9sbGZyb250ZW5kdG9rZW4iLAogICAgICAgICAg
ICAicGFzc3dvcmQiOiJucEFlekV5Nzl5YnRRa2hoS1RobSIsCiAgICAgICAgICAgICJlbWFpbCI6
InZpeGF3ZWJAZ21haWwuY29tIiwKICAgICAgICAgICAgImF1dGgiOiJjR0Y1Y205c2JHWnliMjUw
Wlc1a2RHOXJaVzQ2Ym5CQlpIcEZlVGM1ZVdKMFVXdG9hRXRVYUcwSyIKICAgICAgICB9CiAgICB9
GuYt
- In your deploy file add the secret
apiVersion: apps/v1
kind: Deployment
metadata:
name: payrollfrontend-deployment
labels:
app: payrollfrontend-deployment
spec:
replicas: 1
selector:
matchLabels:
app: payrollfrontend-deployment
template:
metadata:
labels:
app: payrollfrontend-deployment
spec:
containers:
- name: payrollfrontend-deployment
image: registry.gitlab.com/payrollgroup/payrollfrontend:main
imagePullSecrets:
- name: registryfront-credentials
- To see the secret
kubectl get secret registr-credentials -o jsonpath='{.data}'