본문 바로가기

CKA &. CKAD/Application Lifecycle Management

Application Commands & Argument and Practice Test

docker run ubuntu

docker ps

docker ps -a

 

Nignx Docker File

# Install Nginx.
RUN \
  add-apt-repository -y ppa:nginx/stable && \
  apt-get update && \
  apt-get install -y nginx && \
  rm -rf /var/lib/apt/lists/* && \
  echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
  chown -R www-data:www-data /var/lib/nginx
  
# Define mountable directories.
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/

# Define working directory
WORKDIR /etc/nginx

# Define default command/
CMD ["nginx"]

Unbutu Docker File

# Pull base image.
FROM ubuntu:14.04

# Install.
RUN \
  sed -i 's/# \(."multiverse$\)/\1/g' /etc/apt/sources.list && \
  apt-get update && \
  apt-get -y upgrade && \
  apt-get install -y build-essential && \
  apt-get install -y software-properties-commn && \
  apt-get install -y byobu curl git htop man unzip vim wget && \
  rm -rf /var/lib/apt/lists/*
  
# Add files
ADD root/.bashrc /root/.bashrc
ADD root/.gitconfig /root/.gitconfig
ADD root/.scripts /root/.scripts

# Set environment variables.
ENV HOME /root

# Define working directory
WORKDIR /root

# Define working directory
WORKDIR /root

# Define default command
CMD ["bash"]

 

docker run ubuntu [COMMAND]
docker run ubuntu sleep 5

 

[sleep]

FROM Ubuntu
CMD sleep 5

 

 

 

docker run --name ubuntu-sleeper ubuntu-sleeper

 

docker run --name ubuntu-sleepr ubunut-sleeper 10

 

pod-definition.yml

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper-pod
spec:
  containers:
    - name: ubuntu-sleeper
      image: ubuntu-sleeper
      args: ["10"]
kubectl create -f pod-definition.yml

 

[sleep2.0]

FROM Ubuntu

ENTRYPOINT ["sleep"]

CMD ["5"]

 

docker run --name ubuntu-sleeper \
    --entrypoint sleep2.0
    ubuntu-sleeper 10
apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper-pod
spec:
  containers:
    - name: ubuntu-sleeper
      image: ubuntu-sleeper
      command: ["sleep2.0]
      args: ["10"]

 

[Practice Test]

 

ㅁ How many PODs exist on. the system?

kubectl get pods

 

ㅁ What is the command used to run the pod 'ubuntu-sleeper'

kubectl get pod ubuntu-sleeper -o yaml 

spec.containers.command 부분 확인

또는

kubectl describe pod ubuntu-sleeper

확인

 

ㅁ Create a pod with the ubuntu image to run a container to sleep for 5000 seconds. Modify the file ubuntu-sleeper-2.yaml

kubectl get pod ubuntu-sleeper -o yaml > ubuntu-sleeper-2.yaml 
vi ubuntu-sleeper-2.yaml

Pod Name과 Command sleep 부분 변경

kubectl create -f ubuntu-sleeper-2.yaml

 

ㅁ Create a pod using the file named 'ubuntu-sleeper-3.yaml'. There is something worng with it. Try to fix it

- Pod NAme: ubuntu-sleeper-3

- Command: sleep 1200

 

origin ubuntu-sleeper-3.yaml

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper-3
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command:
      - "sleep"
      - 1200

modify ubuntu-sleeper-3.yaml

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu-sleeper-3
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command:
      - sleep
      - "1200"

ㅁ Update pod 'ubuntu-sleeper-3' to sleep for 2000 seconds

delete ubuntu-sleeper-3 pod

modify ubuntu-sleeper-3.yaml 

create ubunut-sleeper-3 pod

 

ㅁ Inspect the two files under directory 'webapp-color'. What command is run at container startup?

 [nginx]

 [Flask run]

 [mysqld]

 [pytnon app.py]

 [sleep 4800]

 

Dockerfile

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

 

ㅁ Inspect the two files under directory 'webapp-color-2'. What command is run at container startup?

 

 [python app.py]

 [python app.py --color blue]

 [python app.py --color red]

 

Dockerfile2

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

CMD ["--color", "red"]

 

ㅁ Inspect the two files under directory 'webapp-color-2'. What command is run at container startup?

Assume the image was created from the Dockerfile in this folder

 [python app.py --color red]

 [python app.py --color green]

 [--color green]

 [python app.py]

 

Dockerfile2

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

CMD ["--color", "red"]

 

webapp-color-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: webapp-green
  labels:
      name: webapp-green
spec:
  containers:
  - name: simple-webapp
    image: kodekloud/webapp-color
    command: ["--color","green"]

container 시작시에 dockers는 CMD를

--color, green 

으로 override 됨

 

ㅁ Inspect the two files under directory 'webapp-color-3'. What command is run at container startup?

  [python app.py --color green]

  [python app-py]

  [--color pink]

  [python app.py --color pink]

 

Docker File

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

CMD ["--color", "red"]

webapp-color-pod-2.yaml

apiVersion: v1
kind: Pod
metadata:
  name: webapp-green
  labels:
      name: webapp-green
spec:
  containers:
  - name: simple-webapp
    image: kodekloud/webapp-color
    command: ["python", "app.py"]
    args: ["--color", "pink"]

 

ㅁ Create a pod with the given specifications. By default it displays a 'blue' background. set the given command line arguments to change it to 'green

 

- Pod Name: webapp-green

- Image: kodekloud/webapp-color

- Command line arguments:  --color=green

kubectl run webapp-green --image=kodekloud/webapp-color --dry-run -o yaml > pod-definition.yaml

pod-definition.yaml에 아래 내용 추가

apiVersion: v1
kind: Pod
metadata:
  name: webapp-green
  labels:
    name: webapp-green
spec:
  containers:
  - name: webapp-green 
    image: Kodekloud/webapp-color
    args:["--color=green"]
kubectl create -f pod-definition.yaml

'CKA &. CKAD > Application Lifecycle Management' 카테고리의 다른 글

Secret Practice Test  (0) 2021.03.27
Secret  (0) 2021.03.27
ConfigMap Practice Test  (0) 2021.03.27
Configure Environment Variable in Applications  (0) 2021.03.27
Rolling Update and Rollout  (0) 2021.03.27