thesuhu

Kubernetes Secret

Oct 11th, 2020 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. # Convert your secret data to a base-64 representation
  2. # Suppose you want to have two pieces of secret data: a username my-app and a password 39528$vdg7Jb.
  3. # First, use a base64 encoding tool to convert your username and password to a base64
  4. echo -n 'my-app' | base64
  5. echo -n '39528$vdg7Jb' | base64
  6.  
  7. # create via file yaml
  8. apiVersion: v1
  9. kind: Secret
  10. metadata:
  11.   name: test-secret
  12. data:
  13.   username: bXktYXBw
  14.   password: Mzk1MjgkdmRnN0pi
  15. # kemudian apply
  16. kubectl apply -f <yaml file>
  17. kubectl get secret test-secret
  18. kubectl describe secret test-secret
  19.  
  20. # create langsung via kubectl
  21. kubectl create secret generic test-secret --from-literal='username=my-app' --from-literal='password=39528$vdg7Jb'
  22.  
  23. # membuat secrets dari single file .env
  24. kubectl create secret generic prod-secrets --from-env-file=env.txt
  25. # You can now use the envFrom like this in your yaml file:
  26. containers:
  27.   - name: django
  28.     image: image/name
  29.     envFrom:
  30.       - secretRef:
  31.          name: prod-secrets
  32.  
  33. # saat deplyoment, jika image yg digunakan private registry, maka perlu membuat secret auth ke private registry
  34. kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
  35.  
  36. kubectl create secret docker-registry gitlabcred --docker-server=registry.gitlab.com --docker-username=myusr --docker-password=mypwd --docker-email=myusr@gmail.com
  37. # note: password $ (dollar) error
  38.  
Add Comment
Please, Sign In to add comment