Merge pull request #612 from pwittrock/book

kubectl book - add `newName` function
This commit is contained in:
Kubernetes Prow Robot 2019-03-14 16:52:57 -07:00 committed by GitHub
commit 77950cb93d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 124 additions and 94 deletions

View File

@ -27,7 +27,7 @@ List the contexts in the kubeconfig file
{% sample lang="yaml" %}
```sh
$ kubectl config get-contexts
deploykubectl config get-contexts
```
```sh
@ -47,7 +47,7 @@ Print information about the current context
{% sample lang="yaml" %}
```sh
$ kubectl config --kubeconfig=config-demo view --minify
deploykubectl config --kubeconfig=config-demo view --minify
```
```yaml
@ -87,7 +87,7 @@ the name of the context.
{% sample lang="yaml" %}
```sh
$ export CLUSTER=us-west2-c; kubectl apply -k ${CLUSTER} --context=${CLUSTER}
deployexport CLUSTER=us-west2-c; kubectl apply -k ${CLUSTER} --context=${CLUSTER}
```
{% endmethod %}
@ -105,9 +105,9 @@ the name of the context.
```sh
# change the context to us-west2-c
$ kubectl config use-context us-west2-c
deploykubectl config use-context us-west2-c
# deploy Resources from the ./us-west2-c/kustomization.yaml
$ kubectl apply -k ./us-west2-c
deploykubectl apply -k ./us-west2-c
```
{% endmethod %}
@ -125,7 +125,7 @@ the name of the directory containing the kubeconfig.
{% sample lang="yaml" %}
```sh
$ kubectl apply -k ./us-west2-c --kubeconfig /path/to/us-west2-c/config
deploykubectl apply -k ./us-west2-c --kubeconfig /path/to/us-west2-c/config
```
{% endmethod %}

View File

@ -17,7 +17,7 @@ made by Apply.
{% sample lang="yaml" %}
```sh
$ kubectl diff -k ./dir/
deploykubectl diff -k ./dir/
```
{% endmethod %}
@ -33,7 +33,7 @@ By default, the "diff" command available in your path will be run with "-u" (uni
{% sample lang="yaml" %}
```sh
$ export KUBECTL_EXTERNAL_DIFF=meld; kubectl diff -k ./dir/
deployexport KUBECTL_EXTERNAL_DIFF=meld; kubectl diff -k ./dir/
```
{% endmethod %}

View File

@ -83,7 +83,7 @@ Techniques:
**Base Branch:**
```bash
$ tree
deploytree
.
├── bases
│   ├── ...
@ -113,7 +113,7 @@ $ tree
**Deploy Branches:**
```bash
$ tree
deploytree
.
├── bases # From Base Branch
│   ├── ...
@ -129,7 +129,7 @@ $ tree
```
```bash
$ tree
deploytree
.
├── bases # From Base Branch
│   ├── ...
@ -141,7 +141,7 @@ $ tree
```
```bash
$ tree
deploytree
.
├── bases # From Base Branch
│   ├── ...
@ -196,7 +196,7 @@ Techniques:
**Base Branch:**
```bash
$ tree
deploytree
.
├── bases
│   ├── ...
@ -226,7 +226,7 @@ $ tree
**Deploy Branches:**
```bash
$ tree
deploytree
.
└── deploy-prod
   ├── us-central
@ -238,7 +238,7 @@ $ tree
```
```bash
$ tree
deploytree
.
└── deploy-staging
└── us-west
@ -246,7 +246,7 @@ $ tree
```
```bash
$ tree
deploytree
.
└── deploy-test
└── us-west

View File

@ -72,7 +72,7 @@ Techniques:
{% sample lang="yaml" %}
```bash
$ tree
deploytree
.
├── bases # Used as a Base only
│   ├── kustomization.yaml

View File

@ -77,7 +77,7 @@ Techniques:
**Base Repository:**
```bash
$ tree
deploytree
.
├── bases # Used as a Base only
│   ├── kustomization.yaml
@ -124,7 +124,7 @@ $ tree
```bash
# sre team
$ tree
deploytree
.
├── prod
│   ├── us-central
@ -137,7 +137,7 @@ $ tree
```bash
# qa team
$ tree
deploytree
.
├── staging # Staging
│   └── us-west
@ -146,7 +146,7 @@ $ tree
```bash
# dev team
$ tree
deploytree
.
└── test # Test
└── us-west

View File

@ -1,5 +1,5 @@
{% panel style="info", title="TL;DR" %}
- Override Base Pod and PodTemplate Image Tags
- Override Base Pod and PodTemplate Image **Names** and **Tags**
- Override Base Pod and PodTemplate Environment Variables and Arguments
{% endpanel %}
@ -21,9 +21,14 @@ Common examples include:
{% method %}
**Use Case:** Different Environments (test, dev, staging, canary, prod) use images with different tags.
Override the tag for an `image` field from a [Pod Template](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/#pod-templates)
in a base by specifying the `images` field in the `kustomization.yaml`. The `newTag` may
be specified to override the image tag for images whose image name matches `name`.
Override the name or tag for an `image` field from a [Pod Template](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/#pod-templates)
in a base by specifying the `images` field in the `kustomization.yaml`.
| Field | Description | Example Field | Example Result |
|-----------|--------------------------------------------------------------------------|----------| --- |
| `name` | Match images with this image name| `name: nginx`| |
| `newTag` | Override the image **tag** or **digest** for images whose image name matches `name` | `newTag: new` | `nginx:old` -> `nginx:new` |
| `newName` | Override the image **name** for images whose image name matches `name` | `newImage: nginx-special` | `nginx:old` -> `nginx-special:old` |
{% sample lang="yaml" %}
**Input:** The `kustomization.yaml` file
@ -35,6 +40,7 @@ bases:
images:
- name: nginx-pod
newTag: 1.15
newName: nginx-pod-2
```
**Base:** Resources to be modified by the `kustomization.yaml`
@ -89,7 +95,7 @@ spec:
containers:
# The image image tag has been changed for the container
- name: nginx
image: nginx-pod:1.15
image: nginx-pod-2:1.15
```
{% endmethod %}

View File

@ -72,10 +72,10 @@ ResourceConfig files using `-f`.
{% sample lang="yaml" %}
```bash
# Apply the Resource Config
$ kubectl apply -k .
deploykubectl apply -k .
# View the Resources
$ kubectl get -k .
deploykubectl get -k .
```
{% endmethod %}

View File

@ -1,5 +1,5 @@
{% panel style="info", title="TL;DR" %}
- Override or set the Tag for Container Images
- Override or set the Name and Tag for Container Images
{% endpanel %}
# Container Images
@ -9,7 +9,7 @@
It may be useful to define the tags of container images which are
used across many Workloads.
- Update the container image tag for multiple Workloads at once
- Update the container image name or tag for multiple Workloads at once
- Increase visibility of the versions of container images being used within
the project
- Set the image tag from external sources - such as environment variables
@ -25,13 +25,21 @@ the `kustomization.yaml` using the `images` field. When `images` are
specified, Apply will override the images whose image name matches `name` with a new
tag.
| Field | Description | Example Field | Example Result |
|-----------|--------------------------------------------------------------------------|----------| --- |
| `name` | Match images with this image name| `name: nginx`| |
| `newTag` | Override the image **tag** or **digest** for images whose image name matches `name` | `newTag: new` | `nginx:old` -> `nginx:new` |
| `newName` | Override the image **name** for images whose image name matches `name` | `newImage: nginx-special` | `nginx:old` -> `nginx-special:old` |
{% method %}
**Example:** Use `images` in the `kustomization.yaml` to update the container
images in `deployment.yaml`
Apply will set the `nginx` image to have the tag `1.8.0` - e.g. `nginx:1.8.0`.
This will set the tag for *all* images matching the *name*.
Apply will set the `nginx` image to have the tag `1.8.0` - e.g. `nginx:1.8.0` and
change the image name to `nginx-special`.
This will set the name and tag for *all* images matching the *name*.
{% sample lang="yaml" %}
**Input:** The kustomization.yaml and deployment.yaml files
@ -43,6 +51,7 @@ kind: Kustomization
images:
- name: nginx # match images with this name
newTag: 1.8.0 # override the tag
newName: nginx-special # override the name
resources:
- deployment.yaml
```
@ -88,13 +97,28 @@ spec:
app: nginx
spec:
containers:
# The image has been changed to include the tag
- image: nginx:1.8.0
# The image has been changed
- image: nginx-special:1.8.0
name: nginx
```
{% endmethod %}
## Setting a Name
{% method %}
The name for an image may be set by specifying `newName` and the name of the old container image.
{% sample lang="yaml" %}
```yaml
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: mycontainerregistry/myimage
newName: differentregistry/myimage
```
{% endmethod %}
## Setting a Tag
{% method %}
@ -141,8 +165,8 @@ download the [kustomize standalone](https://github.com/kubernetes-sigs/kustomize
{% sample lang="yaml" %}
```bash
$ kustomize edit set imagetag foo:$(git log -n 1 --pretty=format:"%H")
$ kubectl apply -f .
deploykustomize edit set imagetag foo:$(git log -n 1 --pretty=format:"%H")
deploykubectl apply -f .
```
{% endmethod %}
@ -155,8 +179,8 @@ It is also possible to set a Tag from an environment variable using the same tec
{% sample lang="yaml" %}
```bash
$ kustomize edit set image foo:$FOO_IMAGE_TAG
$ kubectl apply -f .
deploykustomize edit set image foo:$FOO_IMAGE_TAG
deploykubectl apply -f .
```
{% endmethod %}

View File

@ -15,7 +15,7 @@ Print the logs for a Pod running a single Container
{% sample lang="yaml" %}
```bash
$ kubectl logs echo-c6bc8ccff-nnj52
deploykubectl logs echo-c6bc8ccff-nnj52
```
```bash
@ -42,7 +42,7 @@ Print the logs for all Pods for a Workload
```bash
# Print logs from all containers matching label
$ kubectl logs -l app=nginx
deploykubectl logs -l app=nginx
```
{% endmethod %}
@ -65,7 +65,7 @@ Stream logs from a container.
```bash
# Follow logs from container
$ kubectl logs nginx-78f5d695bd-czm8z -f
deploykubectl logs nginx-78f5d695bd-czm8z -f
```
{% endmethod %}
@ -81,7 +81,7 @@ crashed or are crash looping.
```bash
# Print logs from exited container
$ kubectl logs nginx-78f5d695bd-czm8z -p
deploykubectl logs nginx-78f5d695bd-czm8z -p
```
{% endmethod %}
@ -97,7 +97,7 @@ containers.
```bash
# Print logs from the nginx container in the nginx-78f5d695bd-czm8z Pod
$ kubectl logs nginx-78f5d695bd-czm8z -c nginx
deploykubectl logs nginx-78f5d695bd-czm8z -c nginx
```
{% endmethod %}
@ -112,7 +112,7 @@ Print the logs that occurred after an absolute time.
```bash
# Print logs since a date
$ kubectl logs nginx-78f5d695bd-czm8z --since-time=2018-11-01T15:00:00Z
deploykubectl logs nginx-78f5d695bd-czm8z --since-time=2018-11-01T15:00:00Z
```
{% endmethod %}
@ -134,7 +134,7 @@ Examples:
```bash
# Print logs for the past hour
$ kubectl logs nginx-78f5d695bd-czm8z --since=1h
deploykubectl logs nginx-78f5d695bd-czm8z --since=1h
```
{% endmethod %}
@ -150,7 +150,7 @@ Include timestamps in the log lines
```bash
# Print logs with timestamps
$ kubectl logs -l app=echo --timestamps
deploykubectl logs -l app=echo --timestamps
```
```bash

View File

@ -24,7 +24,7 @@ Copy a local file to a remote Pod in a cluster.
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
deploykubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
```
{% endmethod %}
@ -40,7 +40,7 @@ Copy a remote file from a Pod to a local file.
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo <some-pod>:/tmp/bar
deploykubectl cp /tmp/foo <some-pod>:/tmp/bar
```
{% endmethod %}
@ -55,7 +55,7 @@ Specify the Container within a Pod running multiple containers.
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
deploykubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
```
{% endmethod %}
@ -70,7 +70,7 @@ Set the Pod namespace by prefixing the Pod name with `<namespace>/` .
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
deploykubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
```
{% endmethod %}

View File

@ -35,7 +35,7 @@ To get a Shell in a Container, use the `-t -i` options to get a tty and attach S
{% sample lang="yaml" %}
```bash
$ kubectl exec -t -i nginx-78f5d695bd-czm8z bash
deploykubectl exec -t -i nginx-78f5d695bd-czm8z bash
```
```bash

View File

@ -15,7 +15,7 @@ Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 60
{% sample lang="yaml" %}
```bash
$ kubectl port-forward pod/mypod 5000 6000
deploykubectl port-forward pod/mypod 5000 6000
```
{% endmethod %}
@ -30,7 +30,7 @@ deployment
{% sample lang="yaml" %}
```bash
$ kubectl port-forward deployment/mydeployment 5000 6000
deploykubectl port-forward deployment/mydeployment 5000 6000
```
{% endmethod %}
@ -44,7 +44,7 @@ Listen on port 8888 locally, forwarding to 5000 in the pod
{% sample lang="yaml" %}
```bash
$ kubectl port-forward pod/mypod 8888:5000
deploykubectl port-forward pod/mypod 8888:5000
```
{% endmethod %}
@ -58,7 +58,7 @@ Listen on a random port locally, forwarding to 5000 in the pod
{% sample lang="yaml" %}
```bash
$ kubectl port-forward pod/mypod :5000
deploykubectl port-forward pod/mypod :5000
```
{% endmethod %}
@ -74,7 +74,7 @@ Specify the Container within a Pod running multiple containers.
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
deploykubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
```
{% endmethod %}
@ -90,7 +90,7 @@ Set the Pod namespace by prefixing the Pod name with `<namespace>/` .
{% sample lang="yaml" %}
```bash
$ kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
deploykubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
```
{% endmethod %}

View File

@ -28,13 +28,13 @@ To visit the nginx service go to the Proxy URL at
{% sample lang="yaml" %}
```bash
$ kubectl proxy
deploykubectl proxy
Starting to serve on 127.0.0.1:8001
```
```bash
$ curl http://127.0.0.1:8001/api/v1/namespaces/default/services/nginx/proxy/
deploycurl http://127.0.0.1:8001/api/v1/namespaces/default/services/nginx/proxy/
```
{% endmethod %}
@ -56,7 +56,7 @@ A common usecase is to connect to Services running as part of the cluster itself
Services and their Proxy Urls with `kubectl cluster-info`.
```bash
$ kubectl cluster-info
deploykubectl cluster-info
Kubernetes master is running at https://104.197.5.247
GLBCDefaultBackend is running at https://104.197.5.247/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy

View File

@ -24,7 +24,7 @@ source.
{% sample lang="yaml" %}
```bash
$ kubectl version
deploykubectl version
```
```bash
@ -49,7 +49,7 @@ add-ons.
{% sample lang="yaml" %}
```bash
$ kubectl cluster-info
deploykubectl cluster-info
```
```bash
@ -78,7 +78,7 @@ top nodes and pods.
{% sample lang="yaml" %}
```bash
$ kubectl top node
deploykubectl top node
```
```bash
@ -104,7 +104,7 @@ Print the Resource Types available in the cluster.
{% sample lang="yaml" %}
```bash
$ kubectl api-resources
deploykubectl api-resources
```
```bash
@ -127,7 +127,7 @@ Print the API versions available in the cluster.
{% sample lang="yaml" %}
```bash
$ kubectl api-versions
deploykubectl api-versions
```
```bash
@ -159,7 +159,7 @@ Resource types. This is useful for learning about the type.
{% sample lang="yaml" %}
```bash
$ kubectl explain deployment --api-version apps/v1
deploykubectl explain deployment --api-version apps/v1
```
```bash

View File

@ -19,7 +19,7 @@ Resources, and formats and prints this information on multiple lines.
{% sample lang="yaml" %}
```bash
$ kubectl describe deployments
deploykubectl describe deployments
```
```bash

View File

@ -68,7 +68,7 @@ Print the JSON representation of the first Deployment in the list on a single li
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{.items[0]}{"\n"}'
deploykubectl get deployment.v1.apps -o=jsonpath='{.items[0]}{"\n"}'
```
@ -86,7 +86,7 @@ Print the `metadata.name` field for the first Deployment in the list.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{.items[0].metadata.name}{"\n"}'
deploykubectl get deployment.v1.apps -o=jsonpath='{.items[0].metadata.name}{"\n"}'
```
```bash
@ -104,7 +104,7 @@ For each Deployment, print its `metadata.name` field and a newline afterward.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
deploykubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
```
```bash
@ -123,7 +123,7 @@ For each Deployment, print its `metadata.name` and `.status.availableReplicas`.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.availableReplicas}{"\n"}{end}'
deploykubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.availableReplicas}{"\n"}{end}'
```
```bash
nginx 1
@ -141,7 +141,7 @@ Print the list of Deployments as single line.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{@}{"\n"}'
deploykubectl get deployment.v1.apps -o=jsonpath='{@}{"\n"}'
```
```bash
@ -159,7 +159,7 @@ Print each Deployment on a new line.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{@}{"\n"}{end}'
deploykubectl get deployment.v1.apps -o=jsonpath='{range .items[*]}{@}{"\n"}{end}'
```
```bash

View File

@ -15,7 +15,7 @@ Get all Resources provided by the `kustomization.yaml` in project/.
{% sample lang="yaml" %}
```bash
$ kubectl get -k project/
deploykubectl get -k project/
```
{% endmethod %}
@ -27,7 +27,7 @@ Get all Resources present in the Resource Config for a directory.
{% sample lang="yaml" %}
```bash
$ kubectl get -f configs/
deploykubectl get -f configs/
```
{% endmethod %}
@ -44,17 +44,17 @@ The Singular, Plural, Short Name also apply to *Types with Name* and *Types with
```bash
# Plural
$ kubectl get deployments
deploykubectl get deployments
```
```bash
# Singular
$ kubectl get deployment
deploykubectl get deployment
```
```bash
# Short name
$ kubectl get deploy
deploykubectl get deploy
```
{% endmethod %}
@ -69,11 +69,11 @@ The Group and Version for the Resource are explicit.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments.apps
deploykubectl get deployments.apps
```
```bash
$ kubectl get deployments.v1.apps
deploykubectl get deployments.v1.apps
```
{% endmethod %}
@ -86,7 +86,7 @@ Get named Resources in a namespace for a given type.
{% sample lang="yaml" %}
```bash
$ kubectl get deployment nginx
deploykubectl get deployment nginx
```
{% endmethod %}
@ -98,7 +98,7 @@ Get **all** Resources in a namespace **matching a label select** for a given typ
{% sample lang="yaml" %}
```bash
$ kubectl get deployments -l app=nginx
deploykubectl get deployments -l app=nginx
```
{% endmethod %}
@ -114,7 +114,7 @@ The `---all-namespaces` flag will **fetch Resources from all namespaces**.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments --all-namespaces
deploykubectl get deployments --all-namespaces
```
{% endmethod %}
@ -128,7 +128,7 @@ Get and Describe can accept **multiple Resource types**, and it will print them
{% sample lang="yaml" %}
```bash
$ kubectl get deployments,services
deploykubectl get deployments,services
```
{% endmethod %}
@ -142,7 +142,7 @@ Get and Describe can accept **multiple Resource types and names**.
{% sample lang="yaml" %}
```bash
$ kubectl get kubectl get rc/web service/frontend pods/web-pod-13je7
deploykubectl get kubectl get rc/web service/frontend pods/web-pod-13je7
```
{% endmethod %}
@ -156,7 +156,7 @@ These Resources can be view with the `--include-uninitialized` flag.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments --include-uninitialized
deploykubectl get deployments --include-uninitialized
```
{% endmethod %}
@ -170,7 +170,7 @@ The `--ignore-not-found` flag will cause kubectl to exit 0 if the Resource is no
{% sample lang="yaml" %}
```bash
$ kubectl get deployment nginx --ignore-not-found
deploykubectl get deployment nginx --ignore-not-found
```
{% endmethod %}

View File

@ -32,7 +32,7 @@ Print the Raw Resource formatting it as YAML.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments -o yaml
deploykubectl get deployments -o yaml
```
```yaml
@ -120,7 +120,7 @@ Print the Raw Resource formatting it as JSON.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments -o json
deploykubectl get deployments -o json
```
```json

View File

@ -29,7 +29,7 @@ be a summary of fields.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments nginx
deploykubectl get deployments nginx
```
```bash
@ -52,7 +52,7 @@ be a summary of fields.
{% sample lang="yaml" %}
```bash
$ kubectl get -o=wide deployments nginx
deploykubectl get -o=wide deployments nginx
```
```bash
@ -74,7 +74,7 @@ Print out specific fields as Columns.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments -o custom-columns="Name:metadata.name,Replicas:spec.replicas,Strategy:spec.strategy.type"
deploykubectl get deployments -o custom-columns="Name:metadata.name,Replicas:spec.replicas,Strategy:spec.strategy.type"
```
```bash
@ -112,7 +112,7 @@ Print out all labels on each Resource in a single column (last).
{% sample lang="yaml" %}
```bash
$ kubectl get deployment --show-labels
deploykubectl get deployment --show-labels
```
```bash
@ -135,7 +135,7 @@ they want to know which API is being used.
{% sample lang="yaml" %}
```bash
$ kubectl get deployments --show-kind
deploykubectl get deployments --show-kind
```
```bash