카테고리 없음

[Kubernetes] How to run the Kubernetis Pod

트리스탄1234 2024. 4. 11. 05:55
728x90
반응형

Hello neighbors ^.^
Today, I'm going to post about Pod, one of the Kubernetes resources.

There are three ways to drive a pod.

1. Here's how to execute the command (imperative commands).
This time, let's look at the commands that manage the pod.
First, let's look at three ways to generate the Pod.
The first one is the imperative commands, which are the direct operations of the pod.
Use the run command to run as follows.

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl run my-nginx1 --image=nginx:1.19.3
pod/my-nginx1 created

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod -o wide
NAME        READY   STATUS    RESTARTS   AGE   IP           NODE              NOMINATED NODE   READINESS GATES
my-nginx1   1/1     Running   0          83s   172.17.0.3   ip-172-31-31-84   <none>           <none>

 
2. The number two method is to create a yaml configuration of a command object
1) Define and save the test-pod.yaml file as follows.

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ vi test-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  labels:
    tier: frontend
  name: my-nginx2
spec:
  containers:
  - image: nginx:1.19.3
    name: my-nginx2
    ports:
    - containerPort: 80

2) Run the file you created using the -f option with the create command.

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl create -f nginx2-pod.yaml
pod/my-nginx2 created

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod -o wide
NAME        READY   STATUS    RESTARTS   AGE     IP           NODE              NOMINATED NODE   READINESS GATES
my-nginx1   1/1     Running   0          6m20s   172.17.0.3   ip-172-31-31-84   <none>           <none>
my-nginx2   1/1     Running   0          9s      172.17.0.6   ip-172-31-31-84   <none>           <none>
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$

 
3. The third is to create using the apply and -f options without specifying whether to create or update.
1) Create a yaml file as shown below.

apiVersion: v1
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ vi test-pod.yaml

kind: Pod
metadata:
  labels:
    tier: frontend
  name: my-nginx3
spec:
  containers:
  - image: nginx:1.19.3
    name: my-nginx2
    ports:
    - containerPort: 80

 
2) Now create and query using the apply -f option

ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl apply -f test-pod.yaml
pod/my-nginx3 created
ubuntu@ip-172-31-31-84:~/dockertext2/chap07$ kubectl get pod -o wide
NAME        READY   STATUS    RESTARTS   AGE    IP           NODE              NOMINATED NODE   READINESS GATES
my-nginx1   1/1     Running   0          10m    172.17.0.3   ip-172-31-31-84   <none>           <none>
my-nginx2   1/1     Running   0          4m9s   172.17.0.6   ip-172-31-31-84   <none>           <none>
my-nginx3   1/1     Running   0          7s     172.17.0.7   ip-172-31-31-84   <none>           <none>

 

728x90
반응형