도커의 이미지는 빌드 후 불변의 상태를 갖기 때문에 설정 옵션을 유연하게 변경할 수 없다.
configmap → 설정값(시스템환경변수)/사용자별 별도, 파일/사용자별 별도
secret → 일반적인 username/password, 사설 저장소 접근을 위한 인증
config맵 생성
root@manager:~/k8slab# kubectl create configmap testmap --from-literal k8s=kubernetes --from-literal container=docker
configmap/testmap created
from-literal:입력한것을 그대로 만들겠다
root@manager:~/k8slab# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 123m
testmap 2 28s
root@manager:~/k8slab# kubectl describe cm testmap
Name: testmap
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
container:
----
docker
k8s:
----
kubernetes
Events: <none>
root@manager:~/k8slab# kubectl create cm cmtest1 --from-literal name=gildong --from-literal age=24
configmap/cmtest1 created
root@manager:~/k8slab# kubectl create cm cmtest2 --from-literal name=chulsoo --from-literal age=25
configmap/cmtest2 created
root@manager:~/k8slab# kubectl get cm
NAME DATA AGE
cmtest1 2 63s
cmtest2 2 33s
kube-root-ca.crt 1 154m
testmap 2 31m
cmtest1은 환경변수로 추가
cmtest2는 포드내에 파일로 붙여넣기 할 예정
root@manager:~/k8slab# kubectl describe cm cmtest1
Name: cmtest1
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
age:
----
24
name:
----
gildong
Events: <none>
root@manager:~/k8slab# touch cmtestpod.yaml
root@manager:~/k8slab# vi cmtestpod.yaml
apiVersion: v1
kind: Pod
metadata:
name: cmtestpod
spec:
containers:
- name: cmtestpod-ctn
image: busybox #busybox를 실행하면 해당 명령어가 계속 돌아감(컨테이너가 죽지않게만 돌아가게하
려는 목적)
args: ['tail','-f','/dev/null']
envFrom:
- configMapRef:
name: cmtest1
root@manager:~/k8slab# kubectl apply -f cmtestpod.yaml
pod/cmtestpod created
kubectl get pod
cmtestpod가 돌아가고 있는 것 확인
root@manager:~/k8slab# kubectl exec cmtestpod -- env
...
age=24
name=gildong
...
root@manager:~/k8slab# touch cmtestpodvol.yaml
root@manager:~/k8slab# vi cmtestpodvol.yaml
apiVersion: v1
kind: Pod
metadata:
name: cmtestpodvol
spec:
containers:
- name: cmtestpodvolctn
image: busybox
args: ['tail','-f','/dev/null']
volumeMounts:
- name: cmtestpod-volume
mountPath: /etc/testcm
volumes:
- name: cmtestpod-volume
configMap:
name: cmtest2
/etc/testcm아래에 age, name이 들어가 있을 것이다.
root@manager:~/k8slab# kubectl apply -f cmtestpodvol.yaml
pod/cmtestpodvol created
root@manager:~/k8slab# kubectl get pod
NAME READY STATUS RESTARTS AGE
cmtestpod 1/1 Running 0 11m
cmtestpodvol 1/1 Running 0 50s
root@manager:~/k8slab# kubectl exec cmtestpodvol -- ls /etc/testcm
age
name
root@manager:~/k8slab# kubectl exec cmtestpodvol -- cat /etc/testcm/age
25
5root@manager:~/k8slab# kubectl exec cmtestpodvol -- cat /etc/testcm/name
chulsoo
docker login
user:
pass:
docker login https://reg.test.com
username:
password:
secret은 노드 간 통신에서는 보이지 않지만, Pod 내에서는 clear text로 확인이 된다.
https://kubernetes.io/ko/docs/tasks/configure-pod-container/pull-image-private-registry/
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
docker-registry : 현재 만드는 secret은 일반적이 generic이 아니라 도커 저장소에 접속을 위한 secret으로 사용된다(type 지정)
regcred : secret 이름
private이라면 —docker-server=사설저장소주소, public이면 작성하지 않아도 됨
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: private-reg-container
image: <your-private-image>
imagePullSecrets:
- name: regcred
kubectl create secret generic dockerhub1 --from-file=.dockerconfigjson=/root/.docker/config.json --type=kubernetes.io/dockerconfigjson
root@manager:~# kubectl get secret
NAME TYPE DATA AGE
default-token-sw62x kubernetes.io/service-account-token 3 29h
dockerhub1 kubernetes.io/dockerconfigjson 1 18s
root@manager:~# touch testoracle.yaml
root@manager:~# vi testoracle.yaml
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: test-oracle
image: oraclelinux:latest
imagePullSecrets:
- name: dockerhub1
root@manager:~# kubectl apply -f testoracle.yaml
pod/private-reg created