{"id":6299,"date":"2019-07-26T18:59:25","date_gmt":"2019-07-26T18:59:25","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=6299"},"modified":"2021-11-16T11:11:21","modified_gmt":"2021-11-16T11:11:21","slug":"working-with-kubernetes-cluster-using-kubectl-part-11-probes","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/working-with-kubernetes-cluster-using-kubectl-part-11-probes\/","title":{"rendered":"Working with Kubernetes Cluster using Kubectl Part &#8211; 11 &#8211; Probes"},"content":{"rendered":"\n<p><strong>container-probes.yaml<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: hello-world\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: hello-world\n  template:\n    metadata:\n      labels:\n        app: hello-world\n    spec:\n      containers:\n      - name: hello-world\n        image: gcr.io\/google-samples\/hello-app:1.0\n        ports:\n        - containerPort: 8080\n        livenessProbe:\n          tcpSocket:\n            port: 8080\n          initialDelaySeconds: 10\n          periodSeconds: 5\n        readinessProbe:\n          httpGet:\n            path: \/\n            port: 8080\n          initialDelaySeconds: 10\n          periodSeconds: 5\n<\/code><\/span><\/pre>\n\n\n<p><strong>Commands<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">\n\n<span class=\"hljs-comment\">#Start a watch to see the events associated with our probes.<\/span>\nkubectl get events --watch &amp;\nclear\n\n<span class=\"hljs-comment\">#We have a single container pod app, in a Deployment that has both a liveness probe and a readiness probe<\/span>\nmore container-probes.yaml\n\n<span class=\"hljs-comment\">#Send in our deployment, after 10 seconds, our liveness and readiness probes will fail.<\/span>\n<span class=\"hljs-comment\">#The liveness probe will kill the current pod, and recreate one.<\/span>\nkubectl apply -f container-probes.yaml\n\n<span class=\"hljs-comment\">#kill our watch<\/span>\nfg\nctrl+c\n\n<span class=\"hljs-comment\">#We can see that our container isn't ready 0\/1 and it's Restarts are increasing.<\/span>\nkubectl get pods\n\n<span class=\"hljs-comment\">#Let's figure out what's wrong<\/span>\n<span class=\"hljs-comment\">#1. We can see in the events. The Liveness and Readiness probe failures.<\/span>\n<span class=\"hljs-comment\">#2. Under Containers, Liveness and Readiness, we can see the current configuration. And the current probe configuration. Both are pointing to 8081.<\/span>\n<span class=\"hljs-comment\">#3. Under Containers, Ready and Container Contidtions, we can see that the container isn't ready.<\/span>\n<span class=\"hljs-comment\">#3. Our Container Port is 8080, that's what we want our probes, probings. <\/span>\nkubectl describe pods\n\n<span class=\"hljs-comment\">#So let's go ahead and change the probes to 8080<\/span>\nvi container-probes.yaml\n\n<span class=\"hljs-comment\">#And send that change into the API Server for this deployment.<\/span>\nkubectl apply -f container-probes.yaml\n\n<span class=\"hljs-comment\">#Confirm our probes are pointing to the correct container port now, which is 8080.<\/span>\n \n<span class=\"hljs-comment\">#Let's check our status, a couple of things happened there.<\/span>\n<span class=\"hljs-comment\">#1. Our Deployment ReplicaSet created a NEW Pod, when we pushed in the new deployment configuration.<\/span>\n<span class=\"hljs-comment\">#2. It's not immediately ready because of our initialDelaySeconds which is 10 seconds.<\/span>\n<span class=\"hljs-comment\">#3. If we wait long enough, the livenessProbe will kill the original Pod and it will go away.<\/span>\n<span class=\"hljs-comment\">#4. Leaving us with the one pod in our Deployment's ReplicaSet<\/span>\nkubectl get pods \n\nkubectl delete deployment hello-world\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_76535\"><iframe loading=\"lazy\"  id=\"_ytid_93071\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_76535\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>container-probes.yaml Commands<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4859],"tags":[],"class_list":["post-6299","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=6299"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6299\/revisions"}],"predecessor-version":[{"id":25473,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6299\/revisions\/25473"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=6299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=6299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=6299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}