[쿠버네티스 워크로드] 포드 연습문제 풀어보기

hi·2023년 7월 31일
0

쿠버네티스

목록 보기
21/64
post-custom-banner

연습문제

  • 모든 리소스 삭제
  • yaml을 사용하여 도커이미지 jenkins로 Jenkins-manual 파드를 생성하기
  • Jenkins 파드에서 curl 명령어로 로컬호스트:8080 접속하기
  • Jenkins 포트를 8888로 포트포워딩하기
  • 현재 Jenkins-manual의 설정을 yaml로 출력하기


imkunyoung@master-1:~/yaml$ nano jenkins-manual-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: jenkins-manual
spec:
  containers:
  - name: jenkins
    image: jenkins/jenkins
    ports:
    - containerPort: 8080

imkunyoung@master-1:~/yaml$ kubectl create -f jenkins-manual-pod.yaml
pod/jenkins-manual created



imkunyoung@master-1:~/yaml$ kubectl get pods -w
NAME                  READY   STATUS              RESTARTS   AGE
jenkins-manual        0/1     ContainerCreating   0          4s
static-web-master-1   1/1     Running             0          7m3s
jenkins-manual        1/1     Running             0          9s
imkunyoung@master-1:~/yaml$ kubectl get pods -o wide
NAME                  READY   STATUS    RESTARTS   AGE    IP           NODE       NOMINATED NODE   READINESS GATES
jenkins-manual        1/1     Running   0          3m6s   10.0.1.100   worker-3   <none>           <none>
static-web-master-1   1/1     Running   0          10m    10.0.0.106   master-1   <none>           <none>




imkunyoung@master-1:~/yaml$ curl 10.0.1.100:8080
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
-->

</body></html>                                                                                                                             

or

imkunyoung@master-1:~/yaml$ kubectl exec jenkins-manual -- curl 127.0.0.1:8080 -s
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
-->

</body></html>                                                         


로그 확인

imkunyoung@master-1:~/yaml$ kubectl logs jenkins-manual
Running from: /usr/share/jenkins/jenkins.war
webroot: /var/jenkins_home/war
2023-08-01 00:07:32.563+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2023-08-01 00:07:33.565+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2023-08-01 00:07:33.656+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-10.0.15; built: 2023-04-11T17:25:14.480Z; git: 68017dbd00236bb7e187330d7585a059610f661d; jvm 11.0.19+7
2023-08-01 00:07:34.166+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2023-08-01 00:07:34.247+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: Session workerName=node0
2023-08-01 00:07:35.597+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2023-08-01 00:07:36.113+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@3724b43e{Jenkins v2.416,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2023-08-01 00:07:36.176+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@68ead359{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2023-08-01 00:07:36.250+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started Server@58fb7731{STARTING}[10.0.15,sto=0] @4568ms
2023-08-01 00:07:36.269+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2023-08-01 00:07:37.134+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2023-08-01 00:07:37.207+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2023-08-01 00:07:39.731+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2023-08-01 00:07:39.739+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2023-08-01 00:07:39.750+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2023-08-01 00:07:40.147+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2023-08-01 00:07:40.148+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2023-08-01 00:07:40.149+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2023-08-01 00:07:40.150+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2023-08-01 00:07:40.220+0000 [id=44]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2023-08-01 00:07:41.089+0000 [id=31]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

5a390066509b481cbe33bdd476ca9f34

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2023-08-01 00:07:56.284+0000 [id=30]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2023-08-01 00:07:56.375+0000 [id=22]    INFO    hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2023-08-01 00:07:56.514+0000 [id=44]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2023-08-01 00:07:56.515+0000 [id=44]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1


Jenkins-manual의 설정을 yaml로 출력

imkunyoung@master-1:~/yaml$ kubectl get pods jenkins-manual -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2023-08-01T00:07:22Z"
  name: jenkins-manual
  namespace: default
  resourceVersion: "3626977"
  uid: effab45e-4bb7-4c51-a2b1-44da371cd386
spec:
  containers:
  - image: jenkins/jenkins
    imagePullPolicy: Always
    name: jenkins
    ports:
    - containerPort: 8080
      protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-59vwj
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: worker-3
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-59vwj
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-08-01T00:07:22Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-08-01T00:07:31Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-08-01T00:07:31Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-08-01T00:07:22Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: containerd://36c88a36724f13637e7e0dec2bc5109c793e9e452fa5c47a8a8ea5526ca2ddbb
    image: docker.io/jenkins/jenkins:latest
    imageID: docker.io/jenkins/jenkins@sha256:a628f2b7808ccc9b2f3bb5e8aa87bc534c46d43f6942dea2ef8a247f9ac687a6
    lastState: {}
    name: jenkins
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2023-08-01T00:07:30Z"
  hostIP: 10.138.0.5
  phase: Running
  podIP: 10.0.1.100
  podIPs:
  - ip: 10.0.1.100
  qosClass: BestEffort
  startTime: "2023-08-01T00:07:22Z"


실행 시간 등 확인

imkunyoung@master-1:~/yaml$ kubectl describe pods jenkins-manual
Name:             jenkins-manual
Namespace:        default
Priority:         0
Service Account:  default
Node:             worker-3/10.138.0.5
Start Time:       Tue, 01 Aug 2023 00:07:22 +0000
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.0.1.100
IPs:
  IP:  10.0.1.100
Containers:
  jenkins:
    Container ID:   containerd://36c88a36724f13637e7e0dec2bc5109c793e9e452fa5c47a8a8ea5526ca2ddbb
    Image:          jenkins/jenkins
    Image ID:       docker.io/jenkins/jenkins@sha256:a628f2b7808ccc9b2f3bb5e8aa87bc534c46d43f6942dea2ef8a247f9ac687a6
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 01 Aug 2023 00:07:30 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-59vwj (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-59vwj:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  11m   default-scheduler  Successfully assigned default/jenkins-manual to worker-3
  Normal  Pulling    11m   kubelet            Pulling image "jenkins/jenkins"
  Normal  Pulled     11m   kubelet            Successfully pulled image "jenkins/jenkins" in 7.292743659s (7.292755349s including waiting)
  Normal  Created    11m   kubelet            Created container jenkins
  Normal  Started    11m   kubelet            Started container jenkins


post-custom-banner

0개의 댓글