brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Feb 21. 2023

4. 오라클 클라우드 - 쿠버네티스 -cmd,args


<1> 파드 생성 시 실행 명령(command = 도커의 Entrypoint)과 파라미터(arge = 도커의 Cmd)를 전달

<2> env 전달




<1> 파드 생성 시 실행 명령(command = 도커의 Entrypoint)과 파라미터(arge = 도커의 Cmd)를 전달



1

cmd , args 파일 생성


topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > cmd-args.yaml

> apiVersion: v1

> kind: Pod

> metadata:

>   name: cmd-args

> spec:

>   restartPolicy: OnFailure

>   containers:

>   - image: nginx

>     name: cmd-args-nginx

>     ports:

>     - containerPort: 80

>       protocol: TCP

>     command: ["/bin/echo"]

>     args: ["hello"]

> EOF




2

pod 생성

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f cmd-args.yaml

pod/cmd-args created


3

로그에 결과 확인

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl logs cmd-args

hello


4

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete pod --all

pod "cmd-args" deleted


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod -owide

No resources found in default namespace.




<2> env 전달


pod에 환경 변수 전달

env 사용



1

topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > env.yaml

> apiVersion: v1

> kind: Pod

> metadata:

>   name: mynginx

> spec:

>   containers:

>   - image: nginx:latest

>     name: mynginx

>     ports:

>     - containerPort: 80

>     env:

>     - name: MYPASSWORD

>       value: QWE123

> EOF



2

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f env.yaml

pod/mynginx created


3

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl exec mynginx -- env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

TERM=xterm

HOSTNAME=mynginx

MYPASSWORD=QWE123

KUBERNETES_PORT_443_TCP_PROTO=tcp

KUBERNETES_PORT_12250_TCP=tcp://10.96.0.1:12250

DEPLOYMENT_2048_PORT_80_TCP_PORT=80

KUBERNETES_SERVICE_PORT=443

KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1

DEPLOYMENT_2048_PORT=tcp://10.96.214.121:80

DEPLOYMENT_2048_PORT_80_TCP=tcp://10.96.214.121:80

KUBERNETES_SERVICE_PORT_PROXYMUX=12250

KUBERNETES_SERVICE_PORT_HTTPS=443

KUBERNETES_PORT=tcp://10.96.0.1:443

KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443

KUBERNETES_PORT_12250_TCP_PROTO=tcp

KUBERNETES_PORT_12250_TCP_ADDR=10.96.0.1

DEPLOYMENT_2048_SERVICE_HOST=10.96.214.121

DEPLOYMENT_2048_PORT_80_TCP_ADDR=10.96.214.121

KUBERNETES_SERVICE_HOST=10.96.0.1

KUBERNETES_PORT_12250_TCP_PORT=12250

DEPLOYMENT_2048_SERVICE_PORT=80

DEPLOYMENT_2048_PORT_80_TCP_PROTO=tcp

KUBERNETES_PORT_443_TCP_PORT=443

NGINX_VERSION=1.23.3

NJS_VERSION=0.7.9

PKG_RELEASE=1~bullseye

HOME=/root



4

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl exec mynginx -- env | grep MYPASSWORD

MYPASSWORD=QWE123



5

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl delete pod --all

pod "mynginx" deleted



6

topasvga@cloudshell:~ (ap-seoul-1)$ clear


감사합니다.

브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari