Podコントローラ応用ステップ2

4467 ワード

Kubernetes Podコントローラ応用
コンテナモニタプローブのタイプは3種類あります.
    ExecAction,TCPSockeAction,HTTPGetAction
    kubectl explain pods.spec.containers.livenessProbe
    kubectl explain pods.spec.containers.livenessProbe.execコマンドの実行は成功しました.ステータスコードが成功しなかった場合は成功しました.
exec生存性プローブを使用するには、次の手順に従います.
[root@master test]# kubectl get pod -w
	NAME                          READY     STATUS    RESTARTS   AGE
	client                        1/1       Running   0          1d
	liveness-exec-pod             1/1       Running   5          6m
	myapp-848b5b879b-4xpl7        1/1       Running   0          1d
	myapp-848b5b879b-7gtn4        1/1       Running   0          1d
	myapp-848b5b879b-xtcdd        1/1       Running   0          1d
	nginx-deploy-5b595999-fsxlp   1/1       Running   0          1d
	^C[root@master test]# ls
	liveness-exec.yaml
	[root@master test]# cat liveness-exec.yaml 
	apiVersion: v1
	kind: Pod
	metadata:
	  name: liveness-exec-pod
	  namespace: default
	spec:
	  containers:
	  - name: liveness-exec-container
	    image: busybox:latest
	    imagePullPolicy: IfNotPresent
	    command: ["/bin/sh","-c","touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 3600"]
	    livenessProbe:
	      exec:
	        command: ["test","-e","tmp/healthy"]
	      initialDelaySeconds: 1
	      periodSeconds: 3  #      3 


	kubectl describe pods liveness-exec-pod   pod     
	Restart Count:  3    3  
	Liveness:       exec [test -e tmp/healthy] delay=1s timeout=1s period=3s #success=1 #failure=3

	  pod       
	[root@master test]# kubectl get pod -w
	NAME                          READY     STATUS    RESTARTS   AGE
	client                        1/1       Running   0          1d
	liveness-exec-pod             1/1       Running   5          6m
	myapp-848b5b879b-4xpl7        1/1       Running   0          1d
	myapp-848b5b879b-7gtn4        1/1       Running   0          1d
	myapp-848b5b879b-xtcdd        1/1       Running   0          1d
	nginx-deploy-5b595999-fsxlp   1/1       Running   0          1d

 
tcpSocketを使用してkubectl explain podsを検出する.spec.containers.livenessProbe.tcpSocket
httpGetを使用してkubectl explain podsを検出する.spec.containers.livenessProbe.httpGet
  tcpSocket  
	kubectl explain pods.spec.containers.livenessProbe.tcpSocket

	  httpGet  
	kubectl explain pods.spec.containers.livenessProbe.httpGet

この容器に入ります:kubectl exec-it liveness-httpget--/bin/shこの時私たちは容器の内部でindexを削除します.htmlページ/#rm-f/usr/share/nginx/html/index.html
数秒後、podの情報を再度確認しました.kubectl describe pods liveness-httpget
ログ内容:Restart Count:1 Liveness:http-get http://http/index.html delay=1s timeout=1s period=3s #success=1 #failure=3
再びコンテナに戻ります:L kubectl exec-it liveness-httpget--/bin/shファイルに/usr/share/nginx/html/indexが現れました.html
コンテナが起動したからといって、正常に使用できるとは限らない.redisやtomcatのようなサービスが正常に起動してから使用できるようにする必要がある.この場合、プローブが必要だ.
このとき,Podアプリケーションの状態準備モニタリングを用いた:[root@master test]# cat readiness-httpget.yaml 
apiVersion: v1
	kind: Pod
	metadata:
	  name: readiness-httpget-container
	  namespace: default
	spec:
	  containers:
	  - name: liveness-httpget-container
	    image: ikubernetes/myapp:v1
	    imagePullPolicy: IfNotPresent
	    ports:
	      - name: http
	        containerPort: 80
	    readinessProbe:
	       httpGet:
	         port: http
	         path: /index.html
	       initialDelaySeconds: 1
	       periodSeconds: 3

	  :kubectl create -f readiness-httpget.yaml
	   kubectl get pods       
	         
	kubectl exec -it readiness-httpget -- /bin/sh
	rm -f /usr/share/nginx/html/index.html
	   kubectl get pods      
    # echo "hi">usr/share/nginx/html/index.html
    kubectl get pods
              
           ?
    kubectl explain pods.spec.containers.lifecycle

      busybox   :
    busybox  httpd   ,      ,       ,     httpd  ,         。

    cat poststart-pod.yaml   #     

    [root@master manifests]# cat poststart-pod.yaml 
	apiVersion: v1
	kind: Pod
	metadata:
	  name: poststart-pod
	  namespace: default
	spec:
	  containers:
	  - name: busybox-httpd
	    image: busybox:latest
	    imagePullPolicy: IfNotPresent
	    lifecycle:
	      postStart:
	        exec:
	          command: ['bin/sh','-c','echo Home_Page >> /tmp/index.html']
	    command: ["/bin/httpd"]
	    args: ["-f","-h /tmp"]