{"id":1186,"date":"2020-12-22T12:45:09","date_gmt":"2020-12-22T12:45:09","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1186"},"modified":"2020-12-23T10:16:40","modified_gmt":"2020-12-23T10:16:40","slug":"k8s-deployment","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/12\/22\/k8s-deployment\/","title":{"rendered":"K8S: Deployment"},"content":{"rendered":"\n<p>Time to re-test how to create deployments. It has been sometime, I created some deployments so just checking on how much I remember.<\/p>\n\n\n\n<p>The quick way to always get started is to check the <code>HELP<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"910\" height=\"683\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/12\/Screenshot-2020-05-02-at-3.49.39-PM-edited.png\" alt=\"\" class=\"wp-image-1188\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/12\/Screenshot-2020-05-02-at-3.49.39-PM-edited.png 910w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/12\/Screenshot-2020-05-02-at-3.49.39-PM-edited-300x225.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2020\/12\/Screenshot-2020-05-02-at-3.49.39-PM-edited-768x576.png 768w\" sizes=\"(max-width: 910px) 100vw, 910px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><code>k create --help<\/code><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Create a resource from a file or from stdin. \n\nJSON and YAML formats are accepted.\n\nExamples:\n  # Create a pod using the data in pod.json.\n  kubectl create -f .\/pod.json\n  \n  # Create a pod based on the JSON passed into stdin.\n  cat pod.json | kubectl create -f -\n  \n  # Edit the data in docker-registry.yaml in JSON then create the resource using the edited data.\n  kubectl create -f docker-registry.yaml --edit -o json\n\nAvailable Commands:\n  clusterrole         Create a ClusterRole.\n  clusterrolebinding  Create a ClusterRoleBinding for a particular ClusterRole\n  configmap           Create a configmap from a local file, directory or literal value\n  deployment          Create a deployment with the specified name.\n  job                 Create a job with the specified name.\n  namespace           Create a namespace with the specified name\n  poddisruptionbudget Create a pod disruption budget with the specified name.\n  priorityclass       Create a priorityclass with the specified name.\n  quota               Create a quota with the specified name.\n  role                Create a role with single rule.\n  rolebinding         Create a RoleBinding for a particular Role or ClusterRole\n  secret              Create a secret using specified subcommand\n  service             Create a service using specified subcommand.\n  serviceaccount      Create a service account with the specified name\n\nOptions:\n      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in\nthe template. Only applies to golang and jsonpath output formats.\n      --dry-run=false: If true, only print the object that would be sent, without sending it.\n      --edit=false: Edit the API resource before creating\n  -f, --filename=&#91;]: Filename, directory, or URL to files to use to create the resource\n  -o, --output='': Output format. One of:\njson|yaml|name|template|go-template|go-template-file|templatefile|jsonpath|jsonpath-file.\n      --raw='': Raw URI to POST to the server.  Uses the transport specified by the kubeconfig file.\n      --record=false: Record current kubectl command in the resource annotation. If set to false, do not record the\ncommand. If set to true, record the command. If not set, default to updating the existing annotation value only if one\nalready exists.\n  -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage\nrelated manifests organized within the same directory.\n      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the\nannotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.\n  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)\n      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The\ntemplate format is golang templates &#91;http:\/\/golang.org\/pkg\/text\/template\/#pkg-overview].\n      --validate=true: If true, use a schema to validate the input before sending it\n      --windows-line-endings=false: Only relevant if --edit=true. Defaults to the line ending native to your platform.\n\nUsage:\n  kubectl create -f FILENAME &#91;options]\n\nUse \"kubectl &lt;command&gt; --help\" for more information about a given command.\nUse \"kubectl options\" for a list of global command-line options (applies to all commands).<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>k create deployment <code>&lt;my-deployment<\/code>&gt; --image=&lt;Image-Name&gt; --dry-run=true --allow-missing-template-keys=true -o=yaml<\/code><\/pre>\n\n\n\n<p>The output has been set to YAML to see what it will output and I can use that to create my own deployment.yaml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  creationTimestamp: null\n  labels:\n    app: store-deployment\n  name: store-deployment\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: store-deployment\n  strategy: {}\n  template:\n    metadata:\n      creationTimestamp: null\n      labels:\n        app: store-deployment\n    spec:\n      containers:\n      - image: &lt;Image-Name&gt;:1.0.0\n        name: store-products\n        resources: {}\nstatus: {}\n<\/code><\/pre>\n\n\n\n<p>Once deployment is done Time to create a service<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k create service clusterip store-products --tcp=80:80 -o=json<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"apiVersion\": \"v1\",\n    \"kind\": \"Service\",\n    \"metadata\": {\n        \"creationTimestamp\": \"2020-12-22T12:36:19Z\",\n        \"labels\": {\n            \"app\": \"store-products\"\n        },\n        \"name\": \"store-products\",\n        \"namespace\": \"default\",\n        \"resourceVersion\": \"7436\",\n        \"selfLink\": \"\/api\/v1\/namespaces\/default\/services\/store-products\",\n        \"uid\": \"4adac30d-4452-11eb-b86b-1276d3e8b6fb\"\n    },\n    \"spec\": {\n        \"clusterIP\": \"10.97.209.47\",\n        \"ports\": &#91;\n            {\n                \"name\": \"80-80\",\n                \"port\": 80,\n                \"protocol\": \"TCP\",\n                \"targetPort\": 80\n            }\n        ],\n        \"selector\": {\n            \"app\": \"store-products\"\n        },\n        \"sessionAffinity\": \"None\",\n        \"type\": \"ClusterIP\"\n    },\n    \"status\": {\n        \"loadBalancer\": {}\n    }\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>k exec busybox -- curl -s store-products<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: Service\nmetadata:\n  creationTimestamp: 2020-12-22T12:36:19Z\n  labels:\n    app: store-products\n  name: store-products\n  namespace: default\n  resourceVersion: \"7436\"\n  selfLink: \/api\/v1\/namespaces\/default\/services\/store-products\n  uid: 4adac30d-4452-11eb-b86b-1276d3e8b6fb\nspec:\n  clusterIP: 10.97.209.47\n  ports:\n  - name: 80-80\n    port: 80\n    protocol: TCP\n    targetPort: 80\n  selector:\n    app: store-products\n  sessionAffinity: None\n  type: ClusterIP\nstatus:\n  loadBalancer: {}\n~                     <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Namespace<\/h2>\n\n\n\n<p>It is always a good practice to create components under a specific namespace to avoid name collisions<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k create ns my-shop --dry-run \nnamespace\/my-shop created (dry run)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>k create ns my-shop\nnamespace\/my-shop created<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>k get ns\nNAME          STATUS   AGE\ndefault       Active   152m\nkube-public   Active   152m\nkube-system   Active   152m\nmy-shop       Active   2s<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time to re-test how to create deployments. It has been sometime, I created some deployments so just checking on how much I remember. The quick way to always get started is to check the HELP. k create &#8211;help The output has been set to YAML to see what it will output and I can use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1187,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[131,18,132,96],"class_list":["post-1186","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-deployment","tag-k8s","tag-revisit","tag-service","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1186"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1186\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1187"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}