Merge pull request #32118 from nate-double-u/merged-main-dev-1.24
Merged main into dev-1.24
This commit is contained in:
@@ -154,7 +154,7 @@ deployment.apps/my-deployment created
|
||||
persistentvolumeclaim/my-pvc created
|
||||
```
|
||||
|
||||
If you're interested in learning more about `kubectl`, go ahead and read [kubectl Overview](/docs/reference/kubectl/overview/).
|
||||
If you're interested in learning more about `kubectl`, go ahead and read [Command line tool (kubectl)](/docs/reference/kubectl/).
|
||||
|
||||
## Using labels effectively
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ addressing, and it can be used in combination with other CNI plugins.
|
||||
|
||||
### CNI-Genie from Huawei
|
||||
|
||||
[CNI-Genie](https://github.com/cni-genie/CNI-Genie) is a CNI plugin that enables Kubernetes to [simultaneously have access to different implementations](https://github.com/cni-genie/CNI-Genie/blob/master/docs/multiple-cni-plugins/README.md#what-cni-genie-feature-1-multiple-cni-plugins-enables) of the [Kubernetes network model](/docs/concepts/cluster-administration/networking/#the-kubernetes-network-model) in runtime. This includes any implementation that runs as a [CNI plugin](https://github.com/containernetworking/cni#3rd-party-plugins), such as [Flannel](https://github.com/flannel-io/flannel#flannel), [Calico](https://projectcalico.docs.tigera.io/about/about-calico/), [Weave-net](https://www.weave.works/oss/net/).
|
||||
[CNI-Genie](https://github.com/cni-genie/CNI-Genie) is a CNI plugin that enables Kubernetes to [simultaneously have access to different implementations](https://github.com/cni-genie/CNI-Genie/blob/master/docs/multiple-cni-plugins/README.md#what-cni-genie-feature-1-multiple-cni-plugins-enables) of the [Kubernetes network model](/docs/concepts/cluster-administration/networking/#how-to-implement-the-kubernetes-networking-model) in runtime. This includes any implementation that runs as a [CNI plugin](https://github.com/containernetworking/cni#3rd-party-plugins), such as [Flannel](https://github.com/flannel-io/flannel#flannel), [Calico](https://projectcalico.docs.tigera.io/about/about-calico/), [Weave-net](https://www.weave.works/oss/net/).
|
||||
|
||||
CNI-Genie also supports [assigning multiple IP addresses to a pod](https://github.com/cni-genie/CNI-Genie/blob/master/docs/multiple-ips/README.md#feature-2-extension-cni-genie-multiple-ip-addresses-per-pod), each from a different CNI plugin.
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ many core Kubernetes functions are now built using custom resources, making Kube
|
||||
Custom resources can appear and disappear in a running cluster through dynamic registration,
|
||||
and cluster admins can update custom resources independently of the cluster itself.
|
||||
Once a custom resource is installed, users can create and access its objects using
|
||||
[kubectl](/docs/reference/kubectl/overview/), just as they do for built-in resources like
|
||||
[kubectl](/docs/reference/kubectl/), just as they do for built-in resources like
|
||||
*Pods*.
|
||||
|
||||
## Custom controllers
|
||||
|
||||
@@ -23,7 +23,7 @@ The Kubernetes API lets you query and manipulate the state of API objects in Kub
|
||||
(for example: Pods, Namespaces, ConfigMaps, and Events).
|
||||
|
||||
Most operations can be performed through the
|
||||
[kubectl](/docs/reference/kubectl/overview/) command-line interface or other
|
||||
[kubectl](/docs/reference/kubectl/) command-line interface or other
|
||||
command-line tools, such as
|
||||
[kubeadm](/docs/reference/setup-tools/kubeadm/), which in turn use the
|
||||
API. However, you can also access the API directly using REST calls.
|
||||
|
||||
@@ -83,10 +83,19 @@ In the `.yaml` file for the Kubernetes object you want to create, you'll need to
|
||||
|
||||
The precise format of the object `spec` is different for every Kubernetes object, and contains nested fields specific to that object. The [Kubernetes API Reference](https://kubernetes.io/docs/reference/kubernetes-api/) can help you find the spec format for all of the objects you can create using Kubernetes.
|
||||
|
||||
For example, the reference for Pod details the [`spec` field](/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)
|
||||
for a Pod in the API, and the reference for Deployment details the [`spec` field](/docs/reference/kubernetes-api/workload-resources/deployment-v1/#DeploymentSpec) for Deployments.
|
||||
In those API reference pages you'll see mention of PodSpec and DeploymentSpec. These names are implementation details of the Golang code that Kubernetes uses to implement its API.
|
||||
|
||||
For example, see the [`spec` field](/docs/reference/kubernetes-api/workload-resources/pod-v1/#PodSpec)
|
||||
for the Pod API reference.
|
||||
For each Pod, the `.spec` field specifies the pod and its desired state (such as the container image name for
|
||||
each container within that pod).
|
||||
Another example of an object specification is the
|
||||
[`spec` field](/docs/reference/kubernetes-api/workload-resources/stateful-set-v1/#StatefulSetSpec)
|
||||
for the StatefulSet API. For StatefulSet, the `.spec` field specifies the StatefulSet and
|
||||
its desired state.
|
||||
Within the `.spec` of a StatefulSet is a [template](/docs/concepts/workloads/pods/#pod-templates)
|
||||
for Pod objects. That template describes Pods that the StatefulSet controller will create in order to
|
||||
satisfy the StatefulSet specification.
|
||||
Different kinds of object can also have different `.status`; again, the API reference pages
|
||||
detail the structure of that `.status` field, and its content for each different type of object.
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ updates.
|
||||
## What is a Pod Security Policy?
|
||||
|
||||
A _Pod Security Policy_ is a cluster-level resource that controls security
|
||||
sensitive aspects of the pod specification. The [PodSecurityPolicy](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) objects
|
||||
sensitive aspects of the pod specification. The
|
||||
[PodSecurityPolicy](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) objects
|
||||
define a set of conditions that a pod must run with in order to be accepted into
|
||||
the system, as well as defaults for the related fields. They allow an
|
||||
administrator to control the following:
|
||||
@@ -54,10 +55,10 @@ administrator to control the following:
|
||||
|
||||
## Enabling Pod Security Policies
|
||||
|
||||
Pod security policy control is implemented as an optional [admission
|
||||
controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy).
|
||||
PodSecurityPolicies are enforced by [enabling the admission
|
||||
controller](/docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in),
|
||||
Pod security policy control is implemented as an optional
|
||||
[admission controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy).
|
||||
PodSecurityPolicies are enforced by
|
||||
[enabling the admission controller](/docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in),
|
||||
but doing so without authorizing any policies **will prevent any pods from being created** in the
|
||||
cluster.
|
||||
|
||||
@@ -69,9 +70,9 @@ controller.
|
||||
## Authorizing Policies
|
||||
|
||||
When a PodSecurityPolicy resource is created, it does nothing. In order to use
|
||||
it, the requesting user or target pod's [service
|
||||
account](/docs/tasks/configure-pod-container/configure-service-account/) must be
|
||||
authorized to use the policy, by allowing the `use` verb on the policy.
|
||||
it, the requesting user or target pod's
|
||||
[service account](/docs/tasks/configure-pod-container/configure-service-account/)
|
||||
must be authorized to use the policy, by allowing the `use` verb on the policy.
|
||||
|
||||
Most Kubernetes pods are not created directly by users. Instead, they are
|
||||
typically created indirectly as part of a
|
||||
@@ -132,6 +133,7 @@ subjects:
|
||||
If a `RoleBinding` (not a `ClusterRoleBinding`) is used, it will only grant
|
||||
usage for pods being run in the same namespace as the binding. This can be
|
||||
paired with system groups to grant access to all pods run in the namespace:
|
||||
|
||||
```yaml
|
||||
# Authorize all service accounts in a namespace:
|
||||
- kind: Group
|
||||
@@ -143,45 +145,47 @@ paired with system groups to grant access to all pods run in the namespace:
|
||||
name: system:authenticated
|
||||
```
|
||||
|
||||
For more examples of RBAC bindings, see [Role Binding
|
||||
Examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
|
||||
For a complete example of authorizing a PodSecurityPolicy, see
|
||||
[below](#example).
|
||||
For more examples of RBAC bindings, see
|
||||
[RoleBinding examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
|
||||
For a complete example of authorizing a PodSecurityPolicy, see [below](#example).
|
||||
|
||||
### Recommended Practice
|
||||
|
||||
PodSecurityPolicy is being replaced by a new, simplified `PodSecurity` {{< glossary_tooltip
|
||||
text="admission controller" term_id="admission-controller" >}}. For more details on this change, see
|
||||
[PodSecurityPolicy Deprecation: Past, Present, and
|
||||
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/). Follow these
|
||||
guidelines to simplify migration from PodSecurityPolicy to the new admission controller:
|
||||
PodSecurityPolicy is being replaced by a new, simplified `PodSecurity`
|
||||
{{< glossary_tooltip text="admission controller" term_id="admission-controller" >}}.
|
||||
For more details on this change, see
|
||||
[PodSecurityPolicy Deprecation: Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/).
|
||||
Follow these guidelines to simplify migration from PodSecurityPolicy to the
|
||||
new admission controller:
|
||||
|
||||
1. Limit your PodSecurityPolicies to the policies defined by the [Pod Security Standards](/docs/concepts/security/pod-security-standards):
|
||||
- {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
|
||||
- {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
|
||||
- {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
|
||||
1. Limit your PodSecurityPolicies to the policies defined by the
|
||||
[Pod Security Standards](/docs/concepts/security/pod-security-standards):
|
||||
|
||||
2. Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
|
||||
- {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
|
||||
- {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
|
||||
- {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
|
||||
|
||||
1. Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
|
||||
(where `<namespace>` is the target namespace). For example:
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
# This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: psp-baseline-namespaces
|
||||
roleRef:
|
||||
kind: ClusterRole
|
||||
name: psp-baseline
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
subjects:
|
||||
- kind: Group
|
||||
name: system:serviceaccounts:development
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
- kind: Group
|
||||
name: system:serviceaccounts:canary
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
# This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: psp-baseline-namespaces
|
||||
roleRef:
|
||||
kind: ClusterRole
|
||||
name: psp-baseline
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
subjects:
|
||||
- kind: Group
|
||||
name: system:serviceaccounts:development
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
- kind: Group
|
||||
name: system:serviceaccounts:canary
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
@@ -217,8 +221,8 @@ only non-mutating PodSecurityPolicies are used to validate the pod.
|
||||
|
||||
## Example
|
||||
|
||||
_This example assumes you have a running cluster with the PodSecurityPolicy
|
||||
admission controller enabled and you have cluster admin privileges._
|
||||
This example assumes you have a running cluster with the PodSecurityPolicy
|
||||
admission controller enabled and you have cluster admin privileges.
|
||||
|
||||
### Set up
|
||||
|
||||
@@ -364,12 +368,24 @@ Let's try that again, slightly differently:
|
||||
|
||||
```shell
|
||||
kubectl-user create deployment pause --image=k8s.gcr.io/pause
|
||||
```
|
||||
|
||||
```none
|
||||
deployment "pause" created
|
||||
|
||||
```
|
||||
```shell
|
||||
kubectl-user get pods
|
||||
No resources found.
|
||||
```
|
||||
|
||||
```
|
||||
No resources found.
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl-user get events | head -n 2
|
||||
```
|
||||
|
||||
```
|
||||
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE
|
||||
1m 2m 15 pause-7774d79b5 ReplicaSet Warning FailedCreate replicaset-controller Error creating: pods "pause-7774d79b5-" is forbidden: no providers available to validate pod request
|
||||
```
|
||||
@@ -390,6 +406,9 @@ is `default`:
|
||||
kubectl-admin create rolebinding default:psp:unprivileged \
|
||||
--role=psp:unprivileged \
|
||||
--serviceaccount=psp-example:default
|
||||
```
|
||||
|
||||
```none
|
||||
rolebinding "default:psp:unprivileged" created
|
||||
```
|
||||
|
||||
@@ -398,6 +417,9 @@ eventually succeed in creating the pod:
|
||||
|
||||
```shell
|
||||
kubectl-user get pods --watch
|
||||
```
|
||||
|
||||
```none
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
|
||||
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
|
||||
@@ -411,6 +433,9 @@ Delete the namespace to clean up most of the example resources:
|
||||
|
||||
```shell
|
||||
kubectl-admin delete ns psp-example
|
||||
```
|
||||
|
||||
```
|
||||
namespace "psp-example" deleted
|
||||
```
|
||||
|
||||
@@ -419,6 +444,9 @@ up separately:
|
||||
|
||||
```shell
|
||||
kubectl-admin delete psp example
|
||||
```
|
||||
|
||||
```
|
||||
podsecuritypolicy "example" deleted
|
||||
```
|
||||
|
||||
@@ -435,7 +463,8 @@ several security mechanisms.
|
||||
|
||||
{{< codenew file="policy/restricted-psp.yaml" >}}
|
||||
|
||||
See [Pod Security Standards](/docs/concepts/security/pod-security-standards/#policy-instantiation) for more examples.
|
||||
See [Pod Security Standards](/docs/concepts/security/pod-security-standards/#policy-instantiation)
|
||||
for more examples.
|
||||
|
||||
## Policy Reference
|
||||
|
||||
@@ -471,17 +500,17 @@ and `max`(inclusive). Defaults to no allowed host ports.
|
||||
**Volumes** - Provides a list of allowed volume types. The allowable values
|
||||
correspond to the volume sources that are defined when creating a volume. For
|
||||
the complete list of volume types, see [Types of
|
||||
Volumes](/docs/concepts/storage/volumes/#types-of-volumes). Additionally, `*`
|
||||
may be used to allow all volume types.
|
||||
Volumes](/docs/concepts/storage/volumes/#types-of-volumes). Additionally,
|
||||
`*` may be used to allow all volume types.
|
||||
|
||||
The **recommended minimum set** of allowed volumes for new PSPs are:
|
||||
|
||||
- configMap
|
||||
- downwardAPI
|
||||
- emptyDir
|
||||
- persistentVolumeClaim
|
||||
- secret
|
||||
- projected
|
||||
- `configMap`
|
||||
- `downwardAPI`
|
||||
- `emptyDir`
|
||||
- `persistentVolumeClaim`
|
||||
- `secret`
|
||||
- `projected`
|
||||
|
||||
{{< warning >}}
|
||||
PodSecurityPolicy does not limit the types of `PersistentVolume` objects that
|
||||
@@ -493,10 +522,10 @@ should be granted permission to create `PersistentVolume` objects.
|
||||
**FSGroup** - Controls the supplemental group applied to some volumes.
|
||||
|
||||
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
- *MayRunAs* - Requires at least one `range` to be specified. Allows
|
||||
`FSGroups` to be left unset without providing a default. Validates against
|
||||
all ranges if `FSGroups` is set.
|
||||
`FSGroups` to be left unset without providing a default. Validates against
|
||||
all ranges if `FSGroups` is set.
|
||||
- *RunAsAny* - No default provided. Allows any `fsGroup` ID to be specified.
|
||||
|
||||
**AllowedHostPaths** - This specifies a list of host paths that are allowed
|
||||
@@ -515,7 +544,8 @@ For example:
|
||||
readOnly: true # only allow read-only mounts
|
||||
```
|
||||
|
||||
{{< warning >}}There are many ways a container with unrestricted access to the host
|
||||
{{< warning >}}
|
||||
There are many ways a container with unrestricted access to the host
|
||||
filesystem can escalate privileges, including reading data from other
|
||||
containers, and abusing the credentials of system services, such as Kubelet.
|
||||
|
||||
@@ -556,33 +586,33 @@ spec:
|
||||
**RunAsUser** - Controls which user ID the containers are run with.
|
||||
|
||||
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
- *MustRunAsNonRoot* - Requires that the pod be submitted with a non-zero
|
||||
`runAsUser` or have the `USER` directive defined (using a numeric UID) in the
|
||||
image. Pods which have specified neither `runAsNonRoot` nor `runAsUser` settings
|
||||
will be mutated to set `runAsNonRoot=true`, thus requiring a defined non-zero
|
||||
numeric `USER` directive in the container. No default provided. Setting
|
||||
`allowPrivilegeEscalation=false` is strongly recommended with this strategy.
|
||||
`runAsUser` or have the `USER` directive defined (using a numeric UID) in the
|
||||
image. Pods which have specified neither `runAsNonRoot` nor `runAsUser` settings
|
||||
will be mutated to set `runAsNonRoot=true`, thus requiring a defined non-zero
|
||||
numeric `USER` directive in the container. No default provided. Setting
|
||||
`allowPrivilegeEscalation=false` is strongly recommended with this strategy.
|
||||
- *RunAsAny* - No default provided. Allows any `runAsUser` to be specified.
|
||||
|
||||
**RunAsGroup** - Controls which primary group ID the containers are run with.
|
||||
|
||||
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
- *MayRunAs* - Does not require that RunAsGroup be specified. However, when RunAsGroup
|
||||
is specified, they have to fall in the defined range.
|
||||
is specified, they have to fall in the defined range.
|
||||
- *RunAsAny* - No default provided. Allows any `runAsGroup` to be specified.
|
||||
|
||||
|
||||
**SupplementalGroups** - Controls which group IDs containers add.
|
||||
|
||||
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
minimum value of the first range as the default. Validates against all ranges.
|
||||
- *MayRunAs* - Requires at least one `range` to be specified. Allows
|
||||
`supplementalGroups` to be left unset without providing a default.
|
||||
Validates against all ranges if `supplementalGroups` is set.
|
||||
`supplementalGroups` to be left unset without providing a default.
|
||||
Validates against all ranges if `supplementalGroups` is set.
|
||||
- *RunAsAny* - No default provided. Allows any `supplementalGroups` to be
|
||||
specified.
|
||||
specified.
|
||||
|
||||
### Privilege Escalation
|
||||
|
||||
@@ -627,8 +657,8 @@ added. Capabilities listed in `RequiredDropCapabilities` must not be included in
|
||||
`AllowedCapabilities` or `DefaultAddCapabilities`.
|
||||
|
||||
**DefaultAddCapabilities** - The capabilities which are added to containers by
|
||||
default, in addition to the runtime defaults. See the [Docker
|
||||
documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
|
||||
default, in addition to the runtime defaults. See the
|
||||
[Docker documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
|
||||
for the default list of capabilities when using the Docker runtime.
|
||||
|
||||
### SELinux
|
||||
@@ -655,16 +685,17 @@ denoted as the string `Unmasked`.
|
||||
|
||||
### AppArmor
|
||||
|
||||
Controlled via annotations on the PodSecurityPolicy. Refer to the [AppArmor
|
||||
documentation](/docs/tutorials/clusters/apparmor/#podsecuritypolicy-annotations).
|
||||
Controlled via annotations on the PodSecurityPolicy. Refer to the
|
||||
[AppArmor documentation](/docs/tutorials/security/apparmor/#podsecuritypolicy-annotations).
|
||||
|
||||
### Seccomp
|
||||
|
||||
As of Kubernetes v1.19, you can use the `seccompProfile` field in the
|
||||
`securityContext` of Pods or containers to [control use of seccomp
|
||||
profiles](/docs/tutorials/clusters/seccomp). In prior versions, seccomp was
|
||||
controlled by adding annotations to a Pod. The same PodSecurityPolicies can be
|
||||
used with either version to enforce how these fields or annotations are applied.
|
||||
`securityContext` of Pods or containers to
|
||||
[control use of seccomp profiles](/docs/tutorials/security/seccomp/).
|
||||
In prior versions, seccomp was controlled by adding annotations to a Pod. The
|
||||
same PodSecurityPolicies can be used with either version to enforce how these
|
||||
fields or annotations are applied.
|
||||
|
||||
**seccomp.security.alpha.kubernetes.io/defaultProfileName** - Annotation that
|
||||
specifies the default seccomp profile to apply to containers. Possible values
|
||||
@@ -681,10 +712,10 @@ are:
|
||||
flag is not defined, the default path will be used, which is
|
||||
`<root-dir>/seccomp` where `<root-dir>` is specified by the `--root-dir` flag.
|
||||
|
||||
{{< note >}}
|
||||
{{< note >}}
|
||||
The `--seccomp-profile-root` flag is deprecated since Kubernetes
|
||||
v1.19. Users are encouraged to use the default path.
|
||||
{{< /note >}}
|
||||
{{< /note >}}
|
||||
|
||||
**seccomp.security.alpha.kubernetes.io/allowedProfileNames** - Annotation that
|
||||
specifies which values are allowed for the pod seccomp annotations. Specified as
|
||||
@@ -696,18 +727,22 @@ default cannot be changed.
|
||||
|
||||
By default, all safe sysctls are allowed.
|
||||
|
||||
- `forbiddenSysctls` - excludes specific sysctls. You can forbid a combination of safe and unsafe sysctls in the list. To forbid setting any sysctls, use `*` on its own.
|
||||
- `allowedUnsafeSysctls` - allows specific sysctls that had been disallowed by the default list, so long as these are not listed in `forbiddenSysctls`.
|
||||
- `forbiddenSysctls` - excludes specific sysctls. You can forbid a combination
|
||||
of safe and unsafe sysctls in the list. To forbid setting any sysctls, use
|
||||
`*` on its own.
|
||||
- `allowedUnsafeSysctls` - allows specific sysctls that had been disallowed by
|
||||
the default list, so long as these are not listed in `forbiddenSysctls`.
|
||||
|
||||
Refer to the [Sysctl documentation](
|
||||
/docs/tasks/administer-cluster/sysctl-cluster/#podsecuritypolicy).
|
||||
Refer to the [Sysctl documentation](/docs/tasks/administer-cluster/sysctl-cluster/#podsecuritypolicy).
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
- See [PodSecurityPolicy Deprecation: Past, Present, and
|
||||
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/) to learn about
|
||||
the future of pod security policy.
|
||||
- See [PodSecurityPolicy Deprecation: Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/)
|
||||
to learn about the future of pod security policy.
|
||||
|
||||
- See [Pod Security Standards](/docs/concepts/security/pod-security-standards/) for policy recommendations.
|
||||
- See [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
|
||||
for policy recommendations.
|
||||
|
||||
- Refer to [PodSecurityPolicy reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy)
|
||||
for the API details.
|
||||
|
||||
- Refer to [Pod Security Policy Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) for the api details.
|
||||
|
||||
@@ -6,14 +6,117 @@ weight: 70
|
||||
|
||||
{{< glossary_definition term_id="api-eviction" length="short" >}} </br>
|
||||
|
||||
You can request eviction by directly calling the Eviction API
|
||||
using a client of the kube-apiserver, like the `kubectl drain` command.
|
||||
This creates an `Eviction` object, which causes the API server to terminate the Pod.
|
||||
You can request eviction by calling the Eviction API directly, or programmatically
|
||||
using a client of the {{<glossary_tooltip term_id="kube-apiserver" text="API server">}}, like the `kubectl drain` command. This
|
||||
creates an `Eviction` object, which causes the API server to terminate the Pod.
|
||||
|
||||
API-initiated evictions respect your configured [`PodDisruptionBudgets`](/docs/tasks/run-application/configure-pdb/)
|
||||
and [`terminationGracePeriodSeconds`](/docs/concepts/workloads/pods/pod-lifecycle#pod-termination).
|
||||
|
||||
Using the API to create an Eviction object for a Pod is like performing a
|
||||
policy-controlled [`DELETE` operation](/docs/reference/kubernetes-api/workload-resources/pod-v1/#delete-delete-a-pod)
|
||||
on the Pod.
|
||||
|
||||
## Calling the Eviction API
|
||||
|
||||
You can use a [Kubernetes language client](/docs/tasks/administer-cluster/access-cluster-api/#programmatic-access-to-the-api)
|
||||
to access the Kubernetes API and create an `Eviction` object. To do this, you
|
||||
POST the attempted operation, similar to the following example:
|
||||
|
||||
{{< tabs name="Eviction_example" >}}
|
||||
{{% tab name="policy/v1" %}}
|
||||
{{< note >}}
|
||||
`policy/v1` Eviction is available in v1.22+. Use `policy/v1beta1` with prior releases.
|
||||
{{< /note >}}
|
||||
|
||||
```json
|
||||
{
|
||||
"apiVersion": "policy/v1",
|
||||
"kind": "Eviction",
|
||||
"metadata": {
|
||||
"name": "quux",
|
||||
"namespace": "default"
|
||||
}
|
||||
}
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{% tab name="policy/v1beta1" %}}
|
||||
{{< note >}}
|
||||
Deprecated in v1.22 in favor of `policy/v1`
|
||||
{{< /note >}}
|
||||
|
||||
```json
|
||||
{
|
||||
"apiVersion": "policy/v1beta1",
|
||||
"kind": "Eviction",
|
||||
"metadata": {
|
||||
"name": "quux",
|
||||
"namespace": "default"
|
||||
}
|
||||
}
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{< /tabs >}}
|
||||
|
||||
Alternatively, you can attempt an eviction operation by accessing the API using
|
||||
`curl` or `wget`, similar to the following example:
|
||||
|
||||
```bash
|
||||
curl -v -H 'Content-type: application/json' https://your-cluster-api-endpoint.example/api/v1/namespaces/default/pods/quux/eviction -d @eviction.json
|
||||
```
|
||||
|
||||
## How API-initiated eviction works
|
||||
|
||||
When you request an eviction using the API, the API server performs admission
|
||||
checks and responds in one of the following ways:
|
||||
|
||||
* `200 OK`: the eviction is allowed, the `Eviction` subresource is created, and
|
||||
the Pod is deleted, similar to sending a `DELETE` request to the Pod URL.
|
||||
* `429 Too Many Requests`: the eviction is not currently allowed because of the
|
||||
configured {{<glossary_tooltip term_id="pod-disruption-budget" text="PodDisruptionBudget">}}.
|
||||
You may be able to attempt the eviction again later. You might also see this
|
||||
response because of API rate limiting.
|
||||
* `500 Internal Server Error`: the eviction is not allowed because there is a
|
||||
misconfiguration, like if multiple PodDisruptionBudgets reference the same Pod.
|
||||
|
||||
If the Pod you want to evict isn't part of a workload that has a
|
||||
PodDisruptionBudget, the API server always returns `200 OK` and allows the
|
||||
eviction.
|
||||
|
||||
If the API server allows the eviction, the Pod is deleted as follows:
|
||||
|
||||
1. The `Pod` resource in the API server is updated with a deletion timestamp,
|
||||
after which the API server considers the `Pod` resource to be terminated. The
|
||||
`Pod` resource is also marked with the configured grace period.
|
||||
1. The {{<glossary_tooltip term_id="kubelet" text="kubelet">}} on the node where the local Pod is running notices that the `Pod`
|
||||
resource is marked for termination and starts to gracefully shut down the
|
||||
local Pod.
|
||||
1. While the kubelet is shutting the Pod down, the control plane removes the Pod
|
||||
from {{<glossary_tooltip term_id="endpoint" text="Endpoint">}} and
|
||||
{{<glossary_tooltip term_id="endpoint-slice" text="EndpointSlice">}}
|
||||
objects. As a result, controllers no longer consider the Pod as a valid object.
|
||||
1. After the grace period for the Pod expires, the kubelet forcefully terminates
|
||||
the local Pod.
|
||||
1. The kubelet tells the API server to remove the `Pod` resource.
|
||||
1. The API server deletes the `Pod` resource.
|
||||
|
||||
## Troubleshooting stuck evictions
|
||||
|
||||
In some cases, your applications may enter a broken state, where the Eviction
|
||||
API will only return `429` or `500` responses until you intervene. This can
|
||||
happen if, for example, a ReplicaSet creates pods for your application but new
|
||||
pods do not enter a `Ready` state. You may also notice this behavior in cases
|
||||
where the last evicted Pod had a long termination grace period.
|
||||
|
||||
If you notice stuck evictions, try one of the following solutions:
|
||||
|
||||
* Abort or pause the automated operation causing the issue. Investigate the stuck
|
||||
application before you restart the operation.
|
||||
* Wait a while, then directly delete the Pod from your cluster control plane
|
||||
instead of using the Eviction API.
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
* Learn about [Node-pressure Eviction](/docs/concepts/scheduling-eviction/node-pressure-eviction/)
|
||||
* Learn about [Pod Priority and Preemption](/docs/concepts/scheduling-eviction/pod-priority-preemption/)
|
||||
* Learn how to protect your applications with a [Pod Disruption Budget](/docs/tasks/run-application/configure-pdb/).
|
||||
* Learn about [Node-pressure Eviction](/docs/concepts/scheduling-eviction/node-pressure-eviction/).
|
||||
* Learn about [Pod Priority and Preemption](/docs/concepts/scheduling-eviction/pod-priority-preemption/).
|
||||
|
||||
@@ -167,7 +167,7 @@ To do so, add an `addedAffinity` to the args of the [`NodeAffinity` plugin](/doc
|
||||
in the [scheduler configuration](/docs/reference/scheduling/config/). For example:
|
||||
|
||||
```yaml
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta1
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta3
|
||||
kind: KubeSchedulerConfiguration
|
||||
|
||||
profiles:
|
||||
|
||||
@@ -38,7 +38,7 @@ Below is an example configuration that sets
|
||||
resources `intel.com/foo` and `intel.com/bar`.
|
||||
|
||||
```yaml
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta1
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta3
|
||||
kind: KubeSchedulerConfiguration
|
||||
profiles:
|
||||
# ...
|
||||
|
||||
@@ -255,10 +255,11 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.
|
||||
Deployment also ensures that only a certain number of Pods are created above the desired number of Pods.
|
||||
By default, it ensures that at most 125% of the desired number of Pods are up (25% max surge).
|
||||
|
||||
For example, if you look at the above Deployment closely, you will see that it first created a new Pod,
|
||||
then deleted some old Pods, and created new ones. It does not kill old Pods until a sufficient number of
|
||||
For example, if you look at the above Deployment closely, you will see that it first creates a new Pod,
|
||||
then deletes an old Pod, and creates another new one. It does not kill old Pods until a sufficient number of
|
||||
new Pods have come up, and does not create new Pods until a sufficient number of old Pods have been killed.
|
||||
It makes sure that at least 2 Pods are available and that at max 4 Pods in total are available.
|
||||
It makes sure that at least 3 Pods are available and that at max 4 Pods in total are available. In case of
|
||||
a Deployment with 4 replicas, the number of Pods would be between 3 and 5.
|
||||
|
||||
* Get details of your Deployment:
|
||||
```shell
|
||||
@@ -305,10 +306,17 @@ up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.
|
||||
```
|
||||
Here you see that when you first created the Deployment, it created a ReplicaSet (nginx-deployment-2035384211)
|
||||
and scaled it up to 3 replicas directly. When you updated the Deployment, it created a new ReplicaSet
|
||||
(nginx-deployment-1564180365) and scaled it up to 1 and then scaled down the old ReplicaSet to 2, so that at
|
||||
least 2 Pods were available and at most 4 Pods were created at all times. It then continued scaling up and down
|
||||
the new and the old ReplicaSet, with the same rolling update strategy. Finally, you'll have 3 available replicas
|
||||
in the new ReplicaSet, and the old ReplicaSet is scaled down to 0.
|
||||
(nginx-deployment-1564180365) and scaled it up to 1 and waited for it to come up. Then it scaled down the old ReplicaSet
|
||||
to 2 and scaled up the new ReplicaSet to 2 so that at least 3 Pods were available and at most 4 Pods were created at all times.
|
||||
It then continued scaling up and down the new and the old ReplicaSet, with the same rolling update strategy.
|
||||
Finally, you'll have 3 available replicas in the new ReplicaSet, and the old ReplicaSet is scaled down to 0.
|
||||
|
||||
{{< note >}}
|
||||
Kubernetes doesn't count terminating Pods when calculating the number of `availableReplicas`, which must be between
|
||||
`replicas - maxUnavailable` and `replicas + maxSurge`. As a result, you might notice that there are more Pods than
|
||||
expected during a rollout, and that the total resources consumed by the Deployment is more than `replicas + maxSurge`
|
||||
until the `terminationGracePeriodSeconds` of the terminating Pods expires.
|
||||
{{< /note >}}
|
||||
|
||||
### Rollover (aka multiple updates in-flight)
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ Note that we recommend using Deployments instead of directly using Replica Sets,
|
||||
|
||||
### Deployment (Recommended)
|
||||
|
||||
[`Deployment`](/docs/concepts/workloads/controllers/deployment/) is a higher-level API object that updates its underlying Replica Sets and their Pods. Deployments are recommended if you want the rolling update functionality because, they are declarative, server-side, and have additional features.
|
||||
[`Deployment`](/docs/concepts/workloads/controllers/deployment/) is a higher-level API object that updates its underlying Replica Sets and their Pods. Deployments are recommended if you want the rolling update functionality, because they are declarative, server-side, and have additional features.
|
||||
|
||||
### Bare Pods
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ replication controllers, replica sets or stateful sets that the Pod belongs to.
|
||||
An example configuration might look like follows:
|
||||
|
||||
```yaml
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta1
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta3
|
||||
kind: KubeSchedulerConfiguration
|
||||
|
||||
profiles:
|
||||
@@ -352,7 +352,7 @@ you can disable those defaults by setting `defaultingType` to `List` and leaving
|
||||
empty `defaultConstraints` in the `PodTopologySpread` plugin configuration:
|
||||
|
||||
```yaml
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta1
|
||||
apiVersion: kubescheduler.config.k8s.io/v1beta3
|
||||
kind: KubeSchedulerConfiguration
|
||||
|
||||
profiles:
|
||||
|
||||
@@ -95,9 +95,9 @@ class A,B,C,D,E,F,G,H,M,Q,N,O,P,V grey
|
||||
class S,T,U spacewhite
|
||||
class first,second,third white
|
||||
{{</ mermaid >}}
|
||||
***Figure - Getting started for a new contributor***
|
||||
Figure 1. Getting started for a new contributor.
|
||||
|
||||
The figure above outlines a roadmap for new contributors. You can follow some or all of the steps for `Sign up` and `Review`. Now you are ready to open PRs that achieve your contribution objectives with some listed under `Open PR`. Again, questions are always welcome!
|
||||
Figure 1 outlines a roadmap for new contributors. You can follow some or all of the steps for `Sign up` and `Review`. Now you are ready to open PRs that achieve your contribution objectives with some listed under `Open PR`. Again, questions are always welcome!
|
||||
|
||||
Some tasks require more trust and more access in the Kubernetes organization.
|
||||
See [Participating in SIG Docs](/docs/contribute/participate/) for more details about
|
||||
@@ -105,7 +105,7 @@ roles and permissions.
|
||||
|
||||
## Your first contribution
|
||||
|
||||
You can prepare for your first contribution by reviewing several steps beforehand. The figure below outlines the steps and the details follow.
|
||||
You can prepare for your first contribution by reviewing several steps beforehand. Figure 2 outlines the steps and the details follow.
|
||||
|
||||
<!-- See https://github.com/kubernetes/website/issues/28808 for live-editor URL to this figure -->
|
||||
<!-- You can also cut/paste the mermaid code into the live editor at https://mermaid-js.github.io/mermaid-live-editor to play around with it -->
|
||||
@@ -136,7 +136,7 @@ class A,B,D,E,F,G grey
|
||||
class S,T spacewhite
|
||||
class first,second white
|
||||
{{</ mermaid >}}
|
||||
***Figure - Preparation for your first contribution***
|
||||
Figure 2. Preparation for your first contribution.
|
||||
|
||||
- Read the [Contribution overview](/docs/contribute/new-content/overview/) to
|
||||
learn about the different ways you can contribute.
|
||||
|
||||
@@ -22,6 +22,34 @@ Most of the blog's content is about things happening in the core project, but we
|
||||
|
||||
Anyone can write a blog post and submit it for review.
|
||||
|
||||
### Submit a Post
|
||||
|
||||
Blog posts should not be commercial in nature and should consist of original content that applies broadly to the Kubernetes community.
|
||||
Appropriate blog content includes:
|
||||
|
||||
- New Kubernetes capabilities
|
||||
- Kubernetes projects updates
|
||||
- Updates from Special Interest Groups
|
||||
- Tutorials and walkthroughs
|
||||
- Thought leadership around Kubernetes
|
||||
- Kubernetes Partner OSS integration
|
||||
- **Original content only**
|
||||
|
||||
Unsuitable content includes:
|
||||
|
||||
- Vendor product pitches
|
||||
- Partner updates without an integration and customer story
|
||||
- Syndicated posts (language translations ok)
|
||||
|
||||
To submit a blog post, follow these steps:
|
||||
|
||||
1. [Sign the CLA](https://kubernetes.io/docs/contribute/start/#sign-the-cla) if you have not yet done so.
|
||||
1. Have a look at the Markdown format for existing blog posts in the [website repository](https://github.com/kubernetes/website/tree/master/content/en/blog/_posts).
|
||||
1. Write out your blog post in a text editor of your choice.
|
||||
1. On the same link from step 2, click the Create new file button. Paste your content into the editor. Name the file to match the proposed title of the blog post, but don’t put the date in the file name. The blog reviewers will work with you on the final file name and the date the blog will be published.
|
||||
1. When you save the file, GitHub will walk you through the pull request process.
|
||||
1. A blog post reviewer will review your submission and work with you on feedback and final details. When the blog post is approved, the blog will be scheduled for publication.
|
||||
|
||||
### Guidelines and expectations
|
||||
|
||||
- Blog posts should not be vendor pitches.
|
||||
|
||||
@@ -43,7 +43,7 @@ client libraries:
|
||||
|
||||
## CLI
|
||||
|
||||
* [kubectl](/docs/reference/kubectl/overview/) - Main CLI tool for running commands and managing Kubernetes clusters.
|
||||
* [kubectl](/docs/reference/kubectl/) - Main CLI tool for running commands and managing Kubernetes clusters.
|
||||
* [JSONPath](/docs/reference/kubectl/jsonpath/) - Syntax guide for using [JSONPath expressions](https://goessner.net/articles/JsonPath/) with kubectl.
|
||||
* [kubeadm](/docs/reference/setup-tools/kubeadm/) - CLI tool to easily provision a secure Kubernetes cluster.
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ To set feature gates for a component, such as kubelet, use the `--feature-gates`
|
||||
flag assigned to a list of feature pairs:
|
||||
|
||||
```shell
|
||||
--feature-gates="...,GracefulNodeShutdown=true"
|
||||
--feature-gates=...,GracefulNodeShutdown=true
|
||||
```
|
||||
|
||||
The following tables are a summary of the feature gates that you can set on
|
||||
@@ -622,8 +622,10 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
operations from in-tree plugins to corresponding pre-installed CSI plugins
|
||||
- `CSIMigrationAWS`: Enables shims and translation logic to route volume
|
||||
operations from the AWS-EBS in-tree plugin to EBS CSI plugin. Supports
|
||||
falling back to in-tree EBS plugin if a node does not have EBS CSI plugin
|
||||
installed and configured. Requires CSIMigration feature flag enabled.
|
||||
falling back to in-tree EBS plugin for mount operations to nodes that have
|
||||
the feature disabled or that do not have EBS CSI plugin installed and
|
||||
configured. Does not support falling back for provision operations, for those
|
||||
the CSI plugin must be installed and configured.
|
||||
- `CSIMigrationAWSComplete`: Stops registering the EBS in-tree plugin in
|
||||
kubelet and volume controllers and enables shims and translation logic to
|
||||
route volume operations from the AWS-EBS in-tree plugin to EBS CSI plugin.
|
||||
@@ -633,9 +635,11 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
which prevents the registration of in-tree EBS plugin.
|
||||
- `CSIMigrationAzureDisk`: Enables shims and translation logic to route volume
|
||||
operations from the Azure-Disk in-tree plugin to AzureDisk CSI plugin.
|
||||
Supports falling back to in-tree AzureDisk plugin if a node does not have
|
||||
AzureDisk CSI plugin installed and configured. Requires CSIMigration feature
|
||||
flag enabled.
|
||||
Supports falling back to in-tree AzureDisk plugin for mount operations to
|
||||
nodes that have the feature disabled or that do not have AzureDisk CSI plugin
|
||||
installed and configured. Does not support falling back for provision
|
||||
operations, for those the CSI plugin must be installed and configured.
|
||||
Requires CSIMigration feature flag enabled.
|
||||
- `CSIMigrationAzureDiskComplete`: Stops registering the Azure-Disk in-tree
|
||||
plugin in kubelet and volume controllers and enables shims and translation
|
||||
logic to route volume operations from the Azure-Disk in-tree plugin to
|
||||
@@ -645,9 +649,11 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
`InTreePluginAzureDiskUnregister` feature flag which prevents the registration of in-tree AzureDisk plugin.
|
||||
- `CSIMigrationAzureFile`: Enables shims and translation logic to route volume
|
||||
operations from the Azure-File in-tree plugin to AzureFile CSI plugin.
|
||||
Supports falling back to in-tree AzureFile plugin if a node does not have
|
||||
AzureFile CSI plugin installed and configured. Requires CSIMigration feature
|
||||
flag enabled.
|
||||
Supports falling back to in-tree AzureFile plugin for mount operations to
|
||||
nodes that have the feature disabled or that do not have AzureFile CSI plugin
|
||||
installed and configured. Does not support falling back for provision
|
||||
operations, for those the CSI plugin must be installed and configured.
|
||||
Requires CSIMigration feature flag enabled.
|
||||
- `CSIMigrationAzureFileComplete`: Stops registering the Azure-File in-tree
|
||||
plugin in kubelet and volume controllers and enables shims and translation
|
||||
logic to route volume operations from the Azure-File in-tree plugin to
|
||||
@@ -658,8 +664,11 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
of in-tree AzureFile plugin.
|
||||
- `CSIMigrationGCE`: Enables shims and translation logic to route volume
|
||||
operations from the GCE-PD in-tree plugin to PD CSI plugin. Supports falling
|
||||
back to in-tree GCE plugin if a node does not have PD CSI plugin installed and
|
||||
configured. Requires CSIMigration feature flag enabled.
|
||||
back to in-tree GCE plugin for mount operations to nodes that have the
|
||||
feature disabled or that do not have PD CSI plugin installed and configured.
|
||||
Does not support falling back for provision operations, for those the CSI
|
||||
plugin must be installed and configured. Requires CSIMigration feature flag
|
||||
enabled.
|
||||
- `csiMigrationRBD`: Enables shims and translation logic to route volume
|
||||
operations from the RBD in-tree plugin to Ceph RBD CSI plugin. Requires
|
||||
CSIMigration and csiMigrationRBD feature flags enabled and Ceph CSI plugin
|
||||
@@ -675,8 +684,11 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
been deprecated in favor of the `InTreePluginGCEUnregister` feature flag which prevents the registration of in-tree GCE PD plugin.
|
||||
- `CSIMigrationOpenStack`: Enables shims and translation logic to route volume
|
||||
operations from the Cinder in-tree plugin to Cinder CSI plugin. Supports
|
||||
falling back to in-tree Cinder plugin if a node does not have Cinder CSI
|
||||
plugin installed and configured. Requires CSIMigration feature flag enabled.
|
||||
falling back to in-tree Cinder plugin for mount operations to nodes that have
|
||||
the feature disabled or that do not have Cinder CSI plugin installed and
|
||||
configured. Does not support falling back for provision operations, for those
|
||||
the CSI plugin must be installed and configured. Requires CSIMigration
|
||||
feature flag enabled.
|
||||
- `CSIMigrationOpenStackComplete`: Stops registering the Cinder in-tree plugin in
|
||||
kubelet and volume controllers and enables shims and translation logic to route
|
||||
volume operations from the Cinder in-tree plugin to Cinder CSI plugin.
|
||||
@@ -684,9 +696,12 @@ Each feature gate is designed for enabling/disabling a specific feature:
|
||||
CSI plugin installed and configured on all nodes in the cluster. This flag has
|
||||
been deprecated in favor of the `InTreePluginOpenStackUnregister` feature flag which prevents the registration of in-tree openstack cinder plugin.
|
||||
- `CSIMigrationvSphere`: Enables shims and translation logic to route volume operations
|
||||
from the vSphere in-tree plugin to vSphere CSI plugin.
|
||||
Supports falling back to in-tree vSphere plugin if a node does not have vSphere
|
||||
CSI plugin installed and configured. Requires CSIMigration feature flag enabled.
|
||||
from the vSphere in-tree plugin to vSphere CSI plugin. Supports falling back
|
||||
to in-tree vSphere plugin for mount operations to nodes that have the feature
|
||||
disabled or that do not have vSphere CSI plugin installed and configured.
|
||||
Does not support falling back for provision operations, for those the CSI
|
||||
plugin must be installed and configured. Requires CSIMigration feature flag
|
||||
enabled.
|
||||
- `CSIMigrationvSphereComplete`: Stops registering the vSphere in-tree plugin in kubelet
|
||||
and volume controllers and enables shims and translation logic to route volume operations
|
||||
from the vSphere in-tree plugin to vSphere CSI plugin. Requires CSIMigration and
|
||||
|
||||
@@ -4,16 +4,19 @@ id: kubectl
|
||||
date: 2018-04-12
|
||||
full_link: /docs/user-guide/kubectl-overview/
|
||||
short_description: >
|
||||
A command line tool for communicating with a Kubernetes API server.
|
||||
A command line tool for communicating with a Kubernetes cluster.
|
||||
|
||||
aka:
|
||||
aka:
|
||||
- kubectl
|
||||
tags:
|
||||
- tool
|
||||
- fundamental
|
||||
---
|
||||
A command line tool for communicating with a {{< glossary_tooltip text="Kubernetes API" term_id="kubernetes-api" >}} server.
|
||||
Command line tool for communicating with a Kubernetes cluster's
|
||||
{{< glossary_tooltip text="control plane" term_id="control-plane" >}},
|
||||
using the Kubernetes API.
|
||||
|
||||
<!--more-->
|
||||
|
||||
You can use kubectl to create, inspect, update, and delete Kubernetes objects.
|
||||
You can use `kubectl` to create, inspect, update, and delete Kubernetes objects.
|
||||
|
||||
|
||||
@@ -1,5 +1,556 @@
|
||||
---
|
||||
title: "kubectl"
|
||||
title: Command line tool (kubectl)
|
||||
content_type: reference
|
||||
weight: 60
|
||||
no_list: true
|
||||
card:
|
||||
name: reference
|
||||
weight: 20
|
||||
---
|
||||
|
||||
<!-- overview -->
|
||||
{{< glossary_definition prepend="Kubernetes provides a" term_id="kubectl" length="short" >}}
|
||||
|
||||
This tool is named `kubectl`.
|
||||
|
||||
For configuration, `kubectl` looks for a file named `config` in the `$HOME/.kube` directory.
|
||||
You can specify other [kubeconfig](/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
|
||||
files by setting the `KUBECONFIG` environment variable or by setting the
|
||||
[`--kubeconfig`](/docs/concepts/configuration/organize-cluster-access-kubeconfig/) flag.
|
||||
|
||||
This overview covers `kubectl` syntax, describes the command operations, and provides common examples.
|
||||
For details about each command, including all the supported flags and subcommands, see the
|
||||
[kubectl](/docs/reference/generated/kubectl/kubectl-commands/) reference documentation.
|
||||
|
||||
For installation instructions, see [Installing kubectl](/docs/tasks/tools/#kubectl);
|
||||
for a quick guide, see the [cheat sheet](/docs/reference/kubectl/cheatsheet/).
|
||||
If you're used to using the `docker` command-line tool, [`kubectl` for Docker Users](/docs/reference/kubectl/docker-cli-to-kubectl/) explains some equivalent commands for Kubernetes.
|
||||
|
||||
<!-- body -->
|
||||
|
||||
## Syntax
|
||||
|
||||
Use the following syntax to run `kubectl` commands from your terminal window:
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] [flags]
|
||||
```
|
||||
|
||||
where `command`, `TYPE`, `NAME`, and `flags` are:
|
||||
|
||||
* `command`: Specifies the operation that you want to perform on one or more resources,
|
||||
for example `create`, `get`, `describe`, `delete`.
|
||||
|
||||
* `TYPE`: Specifies the [resource type](#resource-types). Resource types are case-insensitive and
|
||||
you can specify the singular, plural, or abbreviated forms.
|
||||
For example, the following commands produce the same output:
|
||||
|
||||
```shell
|
||||
kubectl get pod pod1
|
||||
kubectl get pods pod1
|
||||
kubectl get po pod1
|
||||
```
|
||||
|
||||
* `NAME`: Specifies the name of the resource. Names are case-sensitive. If the name is omitted, details for all resources are displayed, for example `kubectl get pods`.
|
||||
|
||||
When performing an operation on multiple resources, you can specify each resource by type and name or specify one or more files:
|
||||
|
||||
* To specify resources by type and name:
|
||||
|
||||
* To group resources if they are all the same type: `TYPE1 name1 name2 name<#>`.<br/>
|
||||
Example: `kubectl get pod example-pod1 example-pod2`
|
||||
|
||||
* To specify multiple resource types individually: `TYPE1/name1 TYPE1/name2 TYPE2/name3 TYPE<#>/name<#>`.<br/>
|
||||
Example: `kubectl get pod/example-pod1 replicationcontroller/example-rc1`
|
||||
|
||||
* To specify resources with one or more files: `-f file1 -f file2 -f file<#>`
|
||||
|
||||
* [Use YAML rather than JSON](/docs/concepts/configuration/overview/#general-configuration-tips) since YAML tends to be more user-friendly, especially for configuration files.<br/>
|
||||
Example: `kubectl get -f ./pod.yaml`
|
||||
|
||||
* `flags`: Specifies optional flags. For example, you can use the `-s` or `--server` flags to specify the address and port of the Kubernetes API server.<br/>
|
||||
|
||||
{{< caution >}}
|
||||
Flags that you specify from the command line override default values and any corresponding environment variables.
|
||||
{{< /caution >}}
|
||||
|
||||
If you need help, run `kubectl help` from the terminal window.
|
||||
|
||||
## In-cluster authentication and namespace overrides
|
||||
|
||||
By default `kubectl` will first determine if it is running within a pod, and thus in a cluster. It starts by checking for the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables and the existence of a service account token file at `/var/run/secrets/kubernetes.io/serviceaccount/token`. If all three are found in-cluster authentication is assumed.
|
||||
|
||||
To maintain backwards compatibility, if the `POD_NAMESPACE` environment variable is set during in-cluster authentication it will override the default namespace from the service account token. Any manifests or tools relying on namespace defaulting will be affected by this.
|
||||
|
||||
**`POD_NAMESPACE` environment variable**
|
||||
|
||||
If the `POD_NAMESPACE` environment variable is set, cli operations on namespaced resources will default to the variable value. For example, if the variable is set to `seattle`, `kubectl get pods` would return pods in the `seattle` namespace. This is because pods are a namespaced resource, and no namespace was provided in the command. Review the output of `kubectl api-resources` to determine if a resource is namespaced.
|
||||
|
||||
Explicit use of `--namespace <value>` overrides this behavior.
|
||||
|
||||
**How kubectl handles ServiceAccount tokens**
|
||||
|
||||
If:
|
||||
* there is Kubernetes service account token file mounted at
|
||||
`/var/run/secrets/kubernetes.io/serviceaccount/token`, and
|
||||
* the `KUBERNETES_SERVICE_HOST` environment variable is set, and
|
||||
* the `KUBERNETES_SERVICE_PORT` environment variable is set, and
|
||||
* you don't explicitly specify a namespace on the kubectl command line
|
||||
|
||||
then kubectl assumes it is running in your cluster. The kubectl tool looks up the
|
||||
namespace of that ServiceAccount (this is the same as the namespace of the Pod)
|
||||
and acts against that namespace. This is different from what happens outside of a
|
||||
cluster; when kubectl runs outside a cluster and you don't specify a namespace,
|
||||
the kubectl command acts against the `default` namespace.
|
||||
|
||||
## Operations
|
||||
|
||||
The following table includes short descriptions and the general syntax for all of the `kubectl` operations:
|
||||
|
||||
Operation | Syntax | Description
|
||||
-------------------- | -------------------- | --------------------
|
||||
`alpha` | `kubectl alpha SUBCOMMAND [flags]` | List the available commands that correspond to alpha features, which are not enabled in Kubernetes clusters by default.
|
||||
`annotate` | <code>kubectl annotate (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]</code> | Add or update the annotations of one or more resources.
|
||||
`api-resources` | `kubectl api-resources [flags]` | List the API resources that are available.
|
||||
`api-versions` | `kubectl api-versions [flags]` | List the API versions that are available.
|
||||
`apply` | `kubectl apply -f FILENAME [flags]`| Apply a configuration change to a resource from a file or stdin.
|
||||
`attach` | `kubectl attach POD -c CONTAINER [-i] [-t] [flags]` | Attach to a running container either to view the output stream or interact with the container (stdin).
|
||||
`auth` | `kubectl auth [flags] [options]` | Inspect authorization.
|
||||
`autoscale` | <code>kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]</code> | Automatically scale the set of pods that are managed by a replication controller.
|
||||
`certificate` | `kubectl certificate SUBCOMMAND [options]` | Modify certificate resources.
|
||||
`cluster-info` | `kubectl cluster-info [flags]` | Display endpoint information about the master and services in the cluster.
|
||||
`completion` | `kubectl completion SHELL [options]` | Output shell completion code for the specified shell (bash or zsh).
|
||||
`config` | `kubectl config SUBCOMMAND [flags]` | Modifies kubeconfig files. See the individual subcommands for details.
|
||||
`convert` | `kubectl convert -f FILENAME [options]` | Convert config files between different API versions. Both YAML and JSON formats are accepted. Note - requires `kubectl-convert` plugin to be installed.
|
||||
`cordon` | `kubectl cordon NODE [options]` | Mark node as unschedulable.
|
||||
`cp` | `kubectl cp <file-spec-src> <file-spec-dest> [options]` | Copy files and directories to and from containers.
|
||||
`create` | `kubectl create -f FILENAME [flags]` | Create one or more resources from a file or stdin.
|
||||
`delete` | <code>kubectl delete (-f FILENAME | TYPE [NAME | /NAME | -l label | --all]) [flags]</code> | Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
|
||||
`describe` | <code>kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | /NAME | -l label]) [flags]</code> | Display the detailed state of one or more resources.
|
||||
`diff` | `kubectl diff -f FILENAME [flags]`| Diff file or stdin against live configuration.
|
||||
`drain` | `kubectl drain NODE [options]` | Drain node in preparation for maintenance.
|
||||
`edit` | <code>kubectl edit (-f FILENAME | TYPE NAME | TYPE/NAME) [flags]</code> | Edit and update the definition of one or more resources on the server by using the default editor.
|
||||
`exec` | `kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]` | Execute a command against a container in a pod.
|
||||
`explain` | `kubectl explain [--recursive=false] [flags]` | Get documentation of various resources. For instance pods, nodes, services, etc.
|
||||
`expose` | <code>kubectl expose (-f FILENAME | TYPE NAME | TYPE/NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] [flags]</code> | Expose a replication controller, service, or pod as a new Kubernetes service.
|
||||
`get` | <code>kubectl get (-f FILENAME | TYPE [NAME | /NAME | -l label]) [--watch] [--sort-by=FIELD] [[-o | --output]=OUTPUT_FORMAT] [flags]</code> | List one or more resources.
|
||||
`kustomize` | `kubectl kustomize <dir> [flags] [options]` | List a set of API resources generated from instructions in a kustomization.yaml file. The argument must be the path to the directory containing the file, or a git repository URL with a path suffix specifying same with respect to the repository root.
|
||||
`label` | <code>kubectl label (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]</code> | Add or update the labels of one or more resources.
|
||||
`logs` | `kubectl logs POD [-c CONTAINER] [--follow] [flags]` | Print the logs for a container in a pod.
|
||||
`options` | `kubectl options` | List of global command-line options, which apply to all commands.
|
||||
`patch` | <code>kubectl patch (-f FILENAME | TYPE NAME | TYPE/NAME) --patch PATCH [flags]</code> | Update one or more fields of a resource by using the strategic merge patch process.
|
||||
`plugin` | `kubectl plugin [flags] [options]` | Provides utilities for interacting with plugins.
|
||||
`port-forward` | `kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]` | Forward one or more local ports to a pod.
|
||||
`proxy` | `kubectl proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix] [flags]` | Run a proxy to the Kubernetes API server.
|
||||
`replace` | `kubectl replace -f FILENAME` | Replace a resource from a file or stdin.
|
||||
`rollout` | `kubectl rollout SUBCOMMAND [options]` | Manage the rollout of a resource. Valid resource types include: deployments, daemonsets and statefulsets.
|
||||
`run` | <code>kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client|none] [--overrides=inline-json] [flags]</code> | Run a specified image on the cluster.
|
||||
`scale` | <code>kubectl scale (-f FILENAME | TYPE NAME | TYPE/NAME) --replicas=COUNT [--resource-version=version] [--current-replicas=count] [flags]</code> | Update the size of the specified replication controller.
|
||||
`set` | `kubectl set SUBCOMMAND [options]` | Configure application resources.
|
||||
`taint` | `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N [options]` | Update the taints on one or more nodes.
|
||||
`top` | `kubectl top [flags] [options]` | Display Resource (CPU/Memory/Storage) usage.
|
||||
`uncordon` | `kubectl uncordon NODE [options]` | Mark node as schedulable.
|
||||
`version` | `kubectl version [--client] [flags]` | Display the Kubernetes version running on the client and server.
|
||||
`wait` | <code>kubectl wait ([-f FILENAME] | resource.group/resource.name | resource.group [(-l label | --all)]) [--for=delete|--for condition=available] [options]</code> | Experimental: Wait for a specific condition on one or many resources.
|
||||
|
||||
To learn more about command operations, see the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation.
|
||||
|
||||
## Resource types
|
||||
|
||||
The following table includes a list of all the supported resource types and their abbreviated aliases.
|
||||
|
||||
(This output can be retrieved from `kubectl api-resources`, and was accurate as of Kubernetes 1.19.1.)
|
||||
|
||||
| NAME | SHORTNAMES | APIGROUP | NAMESPACED | KIND |
|
||||
|---|---|---|---|---|
|
||||
| `bindings` | | | true | Binding |
|
||||
| `componentstatuses` | `cs` | | false | ComponentStatus |
|
||||
| `configmaps` | `cm` | | true | ConfigMap |
|
||||
| `endpoints` | `ep` | | true | Endpoints |
|
||||
| `events` | `ev` | | true | Event |
|
||||
| `limitranges` | `limits` | | true | LimitRange |
|
||||
| `namespaces` | `ns` | | false | Namespace |
|
||||
| `nodes` | `no` | | false | Node |
|
||||
| `persistentvolumeclaims` | `pvc` | | true | PersistentVolumeClaim |
|
||||
| `persistentvolumes` | `pv` | | false | PersistentVolume |
|
||||
| `pods` | `po` | | true | Pod |
|
||||
| `podtemplates` | | | true | PodTemplate |
|
||||
| `replicationcontrollers` | `rc` | | true | ReplicationController |
|
||||
| `resourcequotas` | `quota` | | true | ResourceQuota |
|
||||
| `secrets` | | | true | Secret |
|
||||
| `serviceaccounts` | `sa` | | true | ServiceAccount |
|
||||
| `services` | `svc` | | true | Service |
|
||||
| `mutatingwebhookconfigurations` | | admissionregistration.k8s.io | false | MutatingWebhookConfiguration |
|
||||
| `validatingwebhookconfigurations` | | admissionregistration.k8s.io | false | ValidatingWebhookConfiguration |
|
||||
| `customresourcedefinitions` | `crd,crds` | apiextensions.k8s.io | false | CustomResourceDefinition |
|
||||
| `apiservices` | | apiregistration.k8s.io | false | APIService |
|
||||
| `controllerrevisions` | | apps | true | ControllerRevision |
|
||||
| `daemonsets` | `ds` | apps | true | DaemonSet |
|
||||
| `deployments` | `deploy` | apps | true | Deployment |
|
||||
| `replicasets` | `rs` | apps | true | ReplicaSet |
|
||||
| `statefulsets` | `sts` | apps | true | StatefulSet |
|
||||
| `tokenreviews` | | authentication.k8s.io | false | TokenReview |
|
||||
| `localsubjectaccessreviews` | | authorization.k8s.io | true | LocalSubjectAccessReview |
|
||||
| `selfsubjectaccessreviews` | | authorization.k8s.io | false | SelfSubjectAccessReview |
|
||||
| `selfsubjectrulesreviews` | | authorization.k8s.io | false | SelfSubjectRulesReview |
|
||||
| `subjectaccessreviews` | | authorization.k8s.io | false | SubjectAccessReview |
|
||||
| `horizontalpodautoscalers` | `hpa` | autoscaling | true | HorizontalPodAutoscaler |
|
||||
| `cronjobs` | `cj` | batch | true | CronJob |
|
||||
| `jobs` | | batch | true | Job |
|
||||
| `certificatesigningrequests` | `csr` | certificates.k8s.io | false | CertificateSigningRequest |
|
||||
| `leases` | | coordination.k8s.io | true | Lease |
|
||||
| `endpointslices` | | discovery.k8s.io | true | EndpointSlice |
|
||||
| `events` | `ev` | events.k8s.io | true | Event |
|
||||
| `ingresses` | `ing` | extensions | true | Ingress |
|
||||
| `flowschemas` | | flowcontrol.apiserver.k8s.io | false | FlowSchema |
|
||||
| `prioritylevelconfigurations` | | flowcontrol.apiserver.k8s.io | false | PriorityLevelConfiguration |
|
||||
| `ingressclasses` | | networking.k8s.io | false | IngressClass |
|
||||
| `ingresses` | `ing` | networking.k8s.io | true | Ingress |
|
||||
| `networkpolicies` | `netpol` | networking.k8s.io | true | NetworkPolicy |
|
||||
| `runtimeclasses` | | node.k8s.io | false | RuntimeClass |
|
||||
| `poddisruptionbudgets` | `pdb` | policy | true | PodDisruptionBudget |
|
||||
| `podsecuritypolicies` | `psp` | policy | false | PodSecurityPolicy |
|
||||
| `clusterrolebindings` | | rbac.authorization.k8s.io | false | ClusterRoleBinding |
|
||||
| `clusterroles` | | rbac.authorization.k8s.io | false | ClusterRole |
|
||||
| `rolebindings` | | rbac.authorization.k8s.io | true | RoleBinding |
|
||||
| `roles` | | rbac.authorization.k8s.io | true | Role |
|
||||
| `priorityclasses` | `pc` | scheduling.k8s.io | false | PriorityClass |
|
||||
| `csidrivers` | | storage.k8s.io | false | CSIDriver |
|
||||
| `csinodes` | | storage.k8s.io | false | CSINode |
|
||||
| `storageclasses` | `sc` | storage.k8s.io | false | StorageClass |
|
||||
| `volumeattachments` | | storage.k8s.io | false | VolumeAttachment |
|
||||
|
||||
## Output options
|
||||
|
||||
Use the following sections for information about how you can format or sort the output of certain commands. For details about which commands support the various output options, see the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation.
|
||||
|
||||
### Formatting output
|
||||
|
||||
The default output format for all `kubectl` commands is the human readable plain-text format. To output details to your terminal window in a specific format, you can add either the `-o` or `--output` flags to a supported `kubectl` command.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] -o <output_format>
|
||||
```
|
||||
|
||||
Depending on the `kubectl` operation, the following output formats are supported:
|
||||
|
||||
Output format | Description
|
||||
--------------| -----------
|
||||
`-o custom-columns=<spec>` | Print a table using a comma separated list of [custom columns](#custom-columns).
|
||||
`-o custom-columns-file=<filename>` | Print a table using the [custom columns](#custom-columns) template in the `<filename>` file.
|
||||
`-o json` | Output a JSON formatted API object.
|
||||
`-o jsonpath=<template>` | Print the fields defined in a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
|
||||
`-o jsonpath-file=<filename>` | Print the fields defined by the [jsonpath](/docs/reference/kubectl/jsonpath/) expression in the `<filename>` file.
|
||||
`-o name` | Print only the resource name and nothing else.
|
||||
`-o wide` | Output in the plain-text format with any additional information. For pods, the node name is included.
|
||||
`-o yaml` | Output a YAML formatted API object.
|
||||
|
||||
##### Example
|
||||
|
||||
In this example, the following command outputs the details for a single pod as a YAML formatted object:
|
||||
|
||||
```shell
|
||||
kubectl get pod web-pod-13je7 -o yaml
|
||||
```
|
||||
|
||||
Remember: See the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation
|
||||
for details about which output format is supported by each command.
|
||||
|
||||
#### Custom columns
|
||||
|
||||
To define custom columns and output only the details that you want into a table, you can use the `custom-columns` option.
|
||||
You can choose to define the custom columns inline or use a template file: `-o custom-columns=<spec>` or `-o custom-columns-file=<filename>`.
|
||||
|
||||
##### Examples
|
||||
|
||||
Inline:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> -o custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion
|
||||
```
|
||||
|
||||
Template file:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> -o custom-columns-file=template.txt
|
||||
```
|
||||
|
||||
where the `template.txt` file contains:
|
||||
|
||||
```
|
||||
NAME RSRC
|
||||
metadata.name metadata.resourceVersion
|
||||
```
|
||||
The result of running either command is similar to:
|
||||
|
||||
```
|
||||
NAME RSRC
|
||||
submit-queue 610995
|
||||
```
|
||||
|
||||
#### Server-side columns
|
||||
|
||||
`kubectl` supports receiving specific column information from the server about objects.
|
||||
This means that for any given resource, the server will return columns and rows relevant to that resource, for the client to print.
|
||||
This allows for consistent human-readable output across clients used against the same cluster, by having the server encapsulate the details of printing.
|
||||
|
||||
This feature is enabled by default. To disable it, add the
|
||||
`--server-print=false` flag to the `kubectl get` command.
|
||||
|
||||
##### Examples
|
||||
|
||||
To print information about the status of a pod, use a command like the following:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> --server-print=false
|
||||
```
|
||||
|
||||
The output is similar to:
|
||||
|
||||
```
|
||||
NAME AGE
|
||||
pod-name 1m
|
||||
```
|
||||
|
||||
### Sorting list objects
|
||||
|
||||
To output objects to a sorted list in your terminal window, you can add the `--sort-by` flag to a supported `kubectl` command. Sort your objects by specifying any numeric or string field with the `--sort-by` flag. To specify a field, use a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] --sort-by=<jsonpath_exp>
|
||||
```
|
||||
|
||||
##### Example
|
||||
|
||||
To print a list of pods sorted by name, you run:
|
||||
|
||||
```shell
|
||||
kubectl get pods --sort-by=.metadata.name
|
||||
```
|
||||
|
||||
## Examples: Common operations
|
||||
|
||||
Use the following set of examples to help you familiarize yourself with running the commonly used `kubectl` operations:
|
||||
|
||||
`kubectl apply` - Apply or Update a resource from a file or stdin.
|
||||
|
||||
```shell
|
||||
# Create a service using the definition in example-service.yaml.
|
||||
kubectl apply -f example-service.yaml
|
||||
|
||||
# Create a replication controller using the definition in example-controller.yaml.
|
||||
kubectl apply -f example-controller.yaml
|
||||
|
||||
# Create the objects that are defined in any .yaml, .yml, or .json file within the <directory> directory.
|
||||
kubectl apply -f <directory>
|
||||
```
|
||||
|
||||
`kubectl get` - List one or more resources.
|
||||
|
||||
```shell
|
||||
# List all pods in plain-text output format.
|
||||
kubectl get pods
|
||||
|
||||
# List all pods in plain-text output format and include additional information (such as node name).
|
||||
kubectl get pods -o wide
|
||||
|
||||
# List the replication controller with the specified name in plain-text output format. Tip: You can shorten and replace the 'replicationcontroller' resource type with the alias 'rc'.
|
||||
kubectl get replicationcontroller <rc-name>
|
||||
|
||||
# List all replication controllers and services together in plain-text output format.
|
||||
kubectl get rc,services
|
||||
|
||||
# List all daemon sets in plain-text output format.
|
||||
kubectl get ds
|
||||
|
||||
# List all pods running on node server01
|
||||
kubectl get pods --field-selector=spec.nodeName=server01
|
||||
```
|
||||
|
||||
`kubectl describe` - Display detailed state of one or more resources, including the uninitialized ones by default.
|
||||
|
||||
```shell
|
||||
# Display the details of the node with name <node-name>.
|
||||
kubectl describe nodes <node-name>
|
||||
|
||||
# Display the details of the pod with name <pod-name>.
|
||||
kubectl describe pods/<pod-name>
|
||||
|
||||
# Display the details of all the pods that are managed by the replication controller named <rc-name>.
|
||||
# Remember: Any pods that are created by the replication controller get prefixed with the name of the replication controller.
|
||||
kubectl describe pods <rc-name>
|
||||
|
||||
# Describe all pods
|
||||
kubectl describe pods
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
The `kubectl get` command is usually used for retrieving one or more
|
||||
resources of the same resource type. It features a rich set of flags that allows
|
||||
you to customize the output format using the `-o` or `--output` flag, for example.
|
||||
You can specify the `-w` or `--watch` flag to start watching updates to a particular
|
||||
object. The `kubectl describe` command is more focused on describing the many
|
||||
related aspects of a specified resource. It may invoke several API calls to the
|
||||
API server to build a view for the user. For example, the `kubectl describe node`
|
||||
command retrieves not only the information about the node, but also a summary of
|
||||
the pods running on it, the events generated for the node etc.
|
||||
{{< /note >}}
|
||||
|
||||
`kubectl delete` - Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
|
||||
|
||||
```shell
|
||||
# Delete a pod using the type and name specified in the pod.yaml file.
|
||||
kubectl delete -f pod.yaml
|
||||
|
||||
# Delete all the pods and services that have the label '<label-key>=<label-value>'.
|
||||
kubectl delete pods,services -l <label-key>=<label-value>
|
||||
|
||||
# Delete all pods, including uninitialized ones.
|
||||
kubectl delete pods --all
|
||||
```
|
||||
|
||||
`kubectl exec` - Execute a command against a container in a pod.
|
||||
|
||||
```shell
|
||||
# Get output from running 'date' from pod <pod-name>. By default, output is from the first container.
|
||||
kubectl exec <pod-name> -- date
|
||||
|
||||
# Get output from running 'date' in container <container-name> of pod <pod-name>.
|
||||
kubectl exec <pod-name> -c <container-name> -- date
|
||||
|
||||
# Get an interactive TTY and run /bin/bash from pod <pod-name>. By default, output is from the first container.
|
||||
kubectl exec -ti <pod-name> -- /bin/bash
|
||||
```
|
||||
|
||||
`kubectl logs` - Print the logs for a container in a pod.
|
||||
|
||||
```shell
|
||||
# Return a snapshot of the logs from pod <pod-name>.
|
||||
kubectl logs <pod-name>
|
||||
|
||||
# Start streaming the logs from pod <pod-name>. This is similar to the 'tail -f' Linux command.
|
||||
kubectl logs -f <pod-name>
|
||||
```
|
||||
|
||||
`kubectl diff` - View a diff of the proposed updates to a cluster.
|
||||
|
||||
```shell
|
||||
# Diff resources included in "pod.json".
|
||||
kubectl diff -f pod.json
|
||||
|
||||
# Diff file read from stdin.
|
||||
cat service.yaml | kubectl diff -f -
|
||||
```
|
||||
|
||||
## Examples: Creating and using plugins
|
||||
|
||||
Use the following set of examples to help you familiarize yourself with writing and using `kubectl` plugins:
|
||||
|
||||
```shell
|
||||
# create a simple plugin in any language and name the resulting executable file
|
||||
# so that it begins with the prefix "kubectl-"
|
||||
cat ./kubectl-hello
|
||||
```
|
||||
```shell
|
||||
#!/bin/sh
|
||||
|
||||
# this plugin prints the words "hello world"
|
||||
echo "hello world"
|
||||
```
|
||||
With a plugin written, let's make it executable:
|
||||
```bash
|
||||
chmod a+x ./kubectl-hello
|
||||
|
||||
# and move it to a location in our PATH
|
||||
sudo mv ./kubectl-hello /usr/local/bin
|
||||
sudo chown root:root /usr/local/bin
|
||||
|
||||
# You have now created and "installed" a kubectl plugin.
|
||||
# You can begin using this plugin by invoking it from kubectl as if it were a regular command
|
||||
kubectl hello
|
||||
```
|
||||
```
|
||||
hello world
|
||||
```
|
||||
|
||||
```shell
|
||||
# You can "uninstall" a plugin, by removing it from the folder in your
|
||||
# $PATH where you placed it
|
||||
sudo rm /usr/local/bin/kubectl-hello
|
||||
```
|
||||
|
||||
In order to view all of the plugins that are available to `kubectl`, use
|
||||
the `kubectl plugin list` subcommand:
|
||||
|
||||
```shell
|
||||
kubectl plugin list
|
||||
```
|
||||
The output is similar to:
|
||||
```
|
||||
The following kubectl-compatible plugins are available:
|
||||
|
||||
/usr/local/bin/kubectl-hello
|
||||
/usr/local/bin/kubectl-foo
|
||||
/usr/local/bin/kubectl-bar
|
||||
```
|
||||
|
||||
`kubectl plugin list` also warns you about plugins that are not
|
||||
executable, or that are shadowed by other plugins; for example:
|
||||
```shell
|
||||
sudo chmod -x /usr/local/bin/kubectl-foo # remove execute permission
|
||||
kubectl plugin list
|
||||
```
|
||||
```
|
||||
The following kubectl-compatible plugins are available:
|
||||
|
||||
/usr/local/bin/kubectl-hello
|
||||
/usr/local/bin/kubectl-foo
|
||||
- warning: /usr/local/bin/kubectl-foo identified as a plugin, but it is not executable
|
||||
/usr/local/bin/kubectl-bar
|
||||
|
||||
error: one plugin warning was found
|
||||
```
|
||||
|
||||
You can think of plugins as a means to build more complex functionality on top
|
||||
of the existing kubectl commands:
|
||||
|
||||
```shell
|
||||
cat ./kubectl-whoami
|
||||
```
|
||||
The next few examples assume that you already made `kubectl-whoami` have
|
||||
the following contents:
|
||||
```shell
|
||||
#!/bin/bash
|
||||
|
||||
# this plugin makes use of the `kubectl config` command in order to output
|
||||
# information about the current user, based on the currently selected context
|
||||
kubectl config view --template='{{ range .contexts }}{{ if eq .name "'$(kubectl config current-context)'" }}Current user: {{ printf "%s\n" .context.user }}{{ end }}{{ end }}'
|
||||
```
|
||||
|
||||
Running the above command gives you an output containing the user for the
|
||||
current context in your KUBECONFIG file:
|
||||
|
||||
```shell
|
||||
# make the file executable
|
||||
sudo chmod +x ./kubectl-whoami
|
||||
|
||||
# and move it into your PATH
|
||||
sudo mv ./kubectl-whoami /usr/local/bin
|
||||
|
||||
kubectl whoami
|
||||
Current user: plugins-user
|
||||
```
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
* Read the `kubectl` reference documentation:
|
||||
* the kubectl [command reference](/docs/reference/kubectl/kubectl/)
|
||||
* the [command line arguments](/docs/reference/generated/kubectl/kubectl-commands/) reference
|
||||
* Learn about [`kubectl` usage conventions](/docs/reference/kubectl/conventions/)
|
||||
* Read about [JSONPath support](/docs/reference/kubectl/jsonpath/) in kubectl
|
||||
* Read about how to [extend kubectl with plugins](/docs/tasks/extend-kubectl/kubectl-plugins)
|
||||
* To find out more about plugins, take a look at the [example CLI plugin](https://github.com/kubernetes/sample-cli-plugin).
|
||||
|
||||
@@ -5,6 +5,7 @@ reviewers:
|
||||
- krousey
|
||||
- clove
|
||||
content_type: concept
|
||||
weight: 10 # highlight it
|
||||
card:
|
||||
name: reference
|
||||
weight: 30
|
||||
@@ -423,7 +424,7 @@ kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="k8s.gcr.
|
||||
kubectl get pods -A -o=custom-columns='DATA:metadata.*'
|
||||
```
|
||||
|
||||
More examples in the kubectl [reference documentation](/docs/reference/kubectl/overview/#custom-columns).
|
||||
More examples in the kubectl [reference documentation](/docs/reference/kubectl/#custom-columns).
|
||||
|
||||
### Kubectl output verbosity and debugging
|
||||
|
||||
@@ -444,7 +445,7 @@ Verbosity | Description
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
* Read the [kubectl overview](/docs/reference/kubectl/overview/) and learn about [JsonPath](/docs/reference/kubectl/jsonpath).
|
||||
* Read the [kubectl overview](/docs/reference/kubectl/) and learn about [JsonPath](/docs/reference/kubectl/jsonpath).
|
||||
|
||||
* See [kubectl](/docs/reference/kubectl/kubectl/) options.
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
title: JSONPath Support
|
||||
content_type: concept
|
||||
weight: 25
|
||||
---
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
title: kubectl Commands
|
||||
weight: 20
|
||||
---
|
||||
|
||||
[kubectl Command Reference](/docs/reference/generated/kubectl/kubectl-commands/)
|
||||
|
||||
@@ -1,548 +0,0 @@
|
||||
---
|
||||
reviewers:
|
||||
- hw-qiaolei
|
||||
title: Overview of kubectl
|
||||
content_type: concept
|
||||
weight: 20
|
||||
card:
|
||||
name: reference
|
||||
weight: 20
|
||||
---
|
||||
|
||||
<!-- overview -->
|
||||
The kubectl command line tool lets you control Kubernetes clusters.
|
||||
For configuration, `kubectl` looks for a file named `config` in the `$HOME/.kube` directory.
|
||||
You can specify other [kubeconfig](/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
|
||||
files by setting the KUBECONFIG environment variable or by setting the
|
||||
[`--kubeconfig`](/docs/concepts/configuration/organize-cluster-access-kubeconfig/) flag.
|
||||
|
||||
This overview covers `kubectl` syntax, describes the command operations, and provides common examples.
|
||||
For details about each command, including all the supported flags and subcommands, see the
|
||||
[kubectl](/docs/reference/generated/kubectl/kubectl-commands/) reference documentation.
|
||||
For installation instructions see [installing kubectl](/docs/tasks/tools/).
|
||||
|
||||
<!-- body -->
|
||||
|
||||
## Syntax
|
||||
|
||||
Use the following syntax to run `kubectl` commands from your terminal window:
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] [flags]
|
||||
```
|
||||
|
||||
where `command`, `TYPE`, `NAME`, and `flags` are:
|
||||
|
||||
* `command`: Specifies the operation that you want to perform on one or more resources,
|
||||
for example `create`, `get`, `describe`, `delete`.
|
||||
|
||||
* `TYPE`: Specifies the [resource type](#resource-types). Resource types are case-insensitive and
|
||||
you can specify the singular, plural, or abbreviated forms.
|
||||
For example, the following commands produce the same output:
|
||||
|
||||
```shell
|
||||
kubectl get pod pod1
|
||||
kubectl get pods pod1
|
||||
kubectl get po pod1
|
||||
```
|
||||
|
||||
* `NAME`: Specifies the name of the resource. Names are case-sensitive. If the name is omitted, details for all resources are displayed, for example `kubectl get pods`.
|
||||
|
||||
When performing an operation on multiple resources, you can specify each resource by type and name or specify one or more files:
|
||||
|
||||
* To specify resources by type and name:
|
||||
|
||||
* To group resources if they are all the same type: `TYPE1 name1 name2 name<#>`.<br/>
|
||||
Example: `kubectl get pod example-pod1 example-pod2`
|
||||
|
||||
* To specify multiple resource types individually: `TYPE1/name1 TYPE1/name2 TYPE2/name3 TYPE<#>/name<#>`.<br/>
|
||||
Example: `kubectl get pod/example-pod1 replicationcontroller/example-rc1`
|
||||
|
||||
* To specify resources with one or more files: `-f file1 -f file2 -f file<#>`
|
||||
|
||||
* [Use YAML rather than JSON](/docs/concepts/configuration/overview/#general-configuration-tips) since YAML tends to be more user-friendly, especially for configuration files.<br/>
|
||||
Example: `kubectl get -f ./pod.yaml`
|
||||
|
||||
* `flags`: Specifies optional flags. For example, you can use the `-s` or `--server` flags to specify the address and port of the Kubernetes API server.<br/>
|
||||
|
||||
{{< caution >}}
|
||||
Flags that you specify from the command line override default values and any corresponding environment variables.
|
||||
{{< /caution >}}
|
||||
|
||||
If you need help, run `kubectl help` from the terminal window.
|
||||
|
||||
## In-cluster authentication and namespace overrides
|
||||
|
||||
By default `kubectl` will first determine if it is running within a pod, and thus in a cluster. It starts by checking for the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables and the existence of a service account token file at `/var/run/secrets/kubernetes.io/serviceaccount/token`. If all three are found in-cluster authentication is assumed.
|
||||
|
||||
To maintain backwards compatibility, if the `POD_NAMESPACE` environment variable is set during in-cluster authentication it will override the default namespace from the service account token. Any manifests or tools relying on namespace defaulting will be affected by this.
|
||||
|
||||
**`POD_NAMESPACE` environment variable**
|
||||
|
||||
If the `POD_NAMESPACE` environment variable is set, cli operations on namespaced resources will default to the variable value. For example, if the variable is set to `seattle`, `kubectl get pods` would return pods in the `seattle` namespace. This is because pods are a namespaced resource, and no namespace was provided in the command. Review the output of `kubectl api-resources` to determine if a resource is namespaced.
|
||||
|
||||
Explicit use of `--namespace <value>` overrides this behavior.
|
||||
|
||||
**How kubectl handles ServiceAccount tokens**
|
||||
|
||||
If:
|
||||
* there is Kubernetes service account token file mounted at
|
||||
`/var/run/secrets/kubernetes.io/serviceaccount/token`, and
|
||||
* the `KUBERNETES_SERVICE_HOST` environment variable is set, and
|
||||
* the `KUBERNETES_SERVICE_PORT` environment variable is set, and
|
||||
* you don't explicitly specify a namespace on the kubectl command line
|
||||
|
||||
then kubectl assumes it is running in your cluster. The kubectl tool looks up the
|
||||
namespace of that ServiceAccount (this is the same as the namespace of the Pod)
|
||||
and acts against that namespace. This is different from what happens outside of a
|
||||
cluster; when kubectl runs outside a cluster and you don't specify a namespace,
|
||||
the kubectl command acts against the `default` namespace.
|
||||
|
||||
## Operations
|
||||
|
||||
The following table includes short descriptions and the general syntax for all of the `kubectl` operations:
|
||||
|
||||
Operation | Syntax | Description
|
||||
-------------------- | -------------------- | --------------------
|
||||
`alpha` | `kubectl alpha SUBCOMMAND [flags]` | List the available commands that correspond to alpha features, which are not enabled in Kubernetes clusters by default.
|
||||
`annotate` | <code>kubectl annotate (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]</code> | Add or update the annotations of one or more resources.
|
||||
`api-resources` | `kubectl api-resources [flags]` | List the API resources that are available.
|
||||
`api-versions` | `kubectl api-versions [flags]` | List the API versions that are available.
|
||||
`apply` | `kubectl apply -f FILENAME [flags]`| Apply a configuration change to a resource from a file or stdin.
|
||||
`attach` | `kubectl attach POD -c CONTAINER [-i] [-t] [flags]` | Attach to a running container either to view the output stream or interact with the container (stdin).
|
||||
`auth` | `kubectl auth [flags] [options]` | Inspect authorization.
|
||||
`autoscale` | <code>kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]</code> | Automatically scale the set of pods that are managed by a replication controller.
|
||||
`certificate` | `kubectl certificate SUBCOMMAND [options]` | Modify certificate resources.
|
||||
`cluster-info` | `kubectl cluster-info [flags]` | Display endpoint information about the master and services in the cluster.
|
||||
`completion` | `kubectl completion SHELL [options]` | Output shell completion code for the specified shell (bash or zsh).
|
||||
`config` | `kubectl config SUBCOMMAND [flags]` | Modifies kubeconfig files. See the individual subcommands for details.
|
||||
`convert` | `kubectl convert -f FILENAME [options]` | Convert config files between different API versions. Both YAML and JSON formats are accepted. Note - requires `kubectl-convert` plugin to be installed.
|
||||
`cordon` | `kubectl cordon NODE [options]` | Mark node as unschedulable.
|
||||
`cp` | `kubectl cp <file-spec-src> <file-spec-dest> [options]` | Copy files and directories to and from containers.
|
||||
`create` | `kubectl create -f FILENAME [flags]` | Create one or more resources from a file or stdin.
|
||||
`delete` | <code>kubectl delete (-f FILENAME | TYPE [NAME | /NAME | -l label | --all]) [flags]</code> | Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
|
||||
`describe` | <code>kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | /NAME | -l label]) [flags]</code> | Display the detailed state of one or more resources.
|
||||
`diff` | `kubectl diff -f FILENAME [flags]`| Diff file or stdin against live configuration.
|
||||
`drain` | `kubectl drain NODE [options]` | Drain node in preparation for maintenance.
|
||||
`edit` | <code>kubectl edit (-f FILENAME | TYPE NAME | TYPE/NAME) [flags]</code> | Edit and update the definition of one or more resources on the server by using the default editor.
|
||||
`exec` | `kubectl exec POD [-c CONTAINER] [-i] [-t] [flags] [-- COMMAND [args...]]` | Execute a command against a container in a pod.
|
||||
`explain` | `kubectl explain [--recursive=false] [flags]` | Get documentation of various resources. For instance pods, nodes, services, etc.
|
||||
`expose` | <code>kubectl expose (-f FILENAME | TYPE NAME | TYPE/NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] [flags]</code> | Expose a replication controller, service, or pod as a new Kubernetes service.
|
||||
`get` | <code>kubectl get (-f FILENAME | TYPE [NAME | /NAME | -l label]) [--watch] [--sort-by=FIELD] [[-o | --output]=OUTPUT_FORMAT] [flags]</code> | List one or more resources.
|
||||
`kustomize` | `kubectl kustomize <dir> [flags] [options]` | List a set of API resources generated from instructions in a kustomization.yaml file. The argument must be the path to the directory containing the file, or a git repository URL with a path suffix specifying same with respect to the repository root.
|
||||
`label` | <code>kubectl label (-f FILENAME | TYPE NAME | TYPE/NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--overwrite] [--all] [--resource-version=version] [flags]</code> | Add or update the labels of one or more resources.
|
||||
`logs` | `kubectl logs POD [-c CONTAINER] [--follow] [flags]` | Print the logs for a container in a pod.
|
||||
`options` | `kubectl options` | List of global command-line options, which apply to all commands.
|
||||
`patch` | <code>kubectl patch (-f FILENAME | TYPE NAME | TYPE/NAME) --patch PATCH [flags]</code> | Update one or more fields of a resource by using the strategic merge patch process.
|
||||
`plugin` | `kubectl plugin [flags] [options]` | Provides utilities for interacting with plugins.
|
||||
`port-forward` | `kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [flags]` | Forward one or more local ports to a pod.
|
||||
`proxy` | `kubectl proxy [--port=PORT] [--www=static-dir] [--www-prefix=prefix] [--api-prefix=prefix] [flags]` | Run a proxy to the Kubernetes API server.
|
||||
`replace` | `kubectl replace -f FILENAME` | Replace a resource from a file or stdin.
|
||||
`rollout` | `kubectl rollout SUBCOMMAND [options]` | Manage the rollout of a resource. Valid resource types include: deployments, daemonsets and statefulsets.
|
||||
`run` | <code>kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client|none] [--overrides=inline-json] [flags]</code> | Run a specified image on the cluster.
|
||||
`scale` | <code>kubectl scale (-f FILENAME | TYPE NAME | TYPE/NAME) --replicas=COUNT [--resource-version=version] [--current-replicas=count] [flags]</code> | Update the size of the specified replication controller.
|
||||
`set` | `kubectl set SUBCOMMAND [options]` | Configure application resources.
|
||||
`taint` | `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N [options]` | Update the taints on one or more nodes.
|
||||
`top` | `kubectl top [flags] [options]` | Display Resource (CPU/Memory/Storage) usage.
|
||||
`uncordon` | `kubectl uncordon NODE [options]` | Mark node as schedulable.
|
||||
`version` | `kubectl version [--client] [flags]` | Display the Kubernetes version running on the client and server.
|
||||
`wait` | <code>kubectl wait ([-f FILENAME] | resource.group/resource.name | resource.group [(-l label | --all)]) [--for=delete|--for condition=available] [options]</code> | Experimental: Wait for a specific condition on one or many resources.
|
||||
|
||||
To learn more about command operations, see the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation.
|
||||
|
||||
## Resource types
|
||||
|
||||
The following table includes a list of all the supported resource types and their abbreviated aliases.
|
||||
|
||||
(This output can be retrieved from `kubectl api-resources`, and was accurate as of Kubernetes 1.19.1.)
|
||||
|
||||
| NAME | SHORTNAMES | APIGROUP | NAMESPACED | KIND |
|
||||
|---|---|---|---|---|
|
||||
| `bindings` | | | true | Binding |
|
||||
| `componentstatuses` | `cs` | | false | ComponentStatus |
|
||||
| `configmaps` | `cm` | | true | ConfigMap |
|
||||
| `endpoints` | `ep` | | true | Endpoints |
|
||||
| `events` | `ev` | | true | Event |
|
||||
| `limitranges` | `limits` | | true | LimitRange |
|
||||
| `namespaces` | `ns` | | false | Namespace |
|
||||
| `nodes` | `no` | | false | Node |
|
||||
| `persistentvolumeclaims` | `pvc` | | true | PersistentVolumeClaim |
|
||||
| `persistentvolumes` | `pv` | | false | PersistentVolume |
|
||||
| `pods` | `po` | | true | Pod |
|
||||
| `podtemplates` | | | true | PodTemplate |
|
||||
| `replicationcontrollers` | `rc` | | true | ReplicationController |
|
||||
| `resourcequotas` | `quota` | | true | ResourceQuota |
|
||||
| `secrets` | | | true | Secret |
|
||||
| `serviceaccounts` | `sa` | | true | ServiceAccount |
|
||||
| `services` | `svc` | | true | Service |
|
||||
| `mutatingwebhookconfigurations` | | admissionregistration.k8s.io | false | MutatingWebhookConfiguration |
|
||||
| `validatingwebhookconfigurations` | | admissionregistration.k8s.io | false | ValidatingWebhookConfiguration |
|
||||
| `customresourcedefinitions` | `crd,crds` | apiextensions.k8s.io | false | CustomResourceDefinition |
|
||||
| `apiservices` | | apiregistration.k8s.io | false | APIService |
|
||||
| `controllerrevisions` | | apps | true | ControllerRevision |
|
||||
| `daemonsets` | `ds` | apps | true | DaemonSet |
|
||||
| `deployments` | `deploy` | apps | true | Deployment |
|
||||
| `replicasets` | `rs` | apps | true | ReplicaSet |
|
||||
| `statefulsets` | `sts` | apps | true | StatefulSet |
|
||||
| `tokenreviews` | | authentication.k8s.io | false | TokenReview |
|
||||
| `localsubjectaccessreviews` | | authorization.k8s.io | true | LocalSubjectAccessReview |
|
||||
| `selfsubjectaccessreviews` | | authorization.k8s.io | false | SelfSubjectAccessReview |
|
||||
| `selfsubjectrulesreviews` | | authorization.k8s.io | false | SelfSubjectRulesReview |
|
||||
| `subjectaccessreviews` | | authorization.k8s.io | false | SubjectAccessReview |
|
||||
| `horizontalpodautoscalers` | `hpa` | autoscaling | true | HorizontalPodAutoscaler |
|
||||
| `cronjobs` | `cj` | batch | true | CronJob |
|
||||
| `jobs` | | batch | true | Job |
|
||||
| `certificatesigningrequests` | `csr` | certificates.k8s.io | false | CertificateSigningRequest |
|
||||
| `leases` | | coordination.k8s.io | true | Lease |
|
||||
| `endpointslices` | | discovery.k8s.io | true | EndpointSlice |
|
||||
| `events` | `ev` | events.k8s.io | true | Event |
|
||||
| `ingresses` | `ing` | extensions | true | Ingress |
|
||||
| `flowschemas` | | flowcontrol.apiserver.k8s.io | false | FlowSchema |
|
||||
| `prioritylevelconfigurations` | | flowcontrol.apiserver.k8s.io | false | PriorityLevelConfiguration |
|
||||
| `ingressclasses` | | networking.k8s.io | false | IngressClass |
|
||||
| `ingresses` | `ing` | networking.k8s.io | true | Ingress |
|
||||
| `networkpolicies` | `netpol` | networking.k8s.io | true | NetworkPolicy |
|
||||
| `runtimeclasses` | | node.k8s.io | false | RuntimeClass |
|
||||
| `poddisruptionbudgets` | `pdb` | policy | true | PodDisruptionBudget |
|
||||
| `podsecuritypolicies` | `psp` | policy | false | PodSecurityPolicy |
|
||||
| `clusterrolebindings` | | rbac.authorization.k8s.io | false | ClusterRoleBinding |
|
||||
| `clusterroles` | | rbac.authorization.k8s.io | false | ClusterRole |
|
||||
| `rolebindings` | | rbac.authorization.k8s.io | true | RoleBinding |
|
||||
| `roles` | | rbac.authorization.k8s.io | true | Role |
|
||||
| `priorityclasses` | `pc` | scheduling.k8s.io | false | PriorityClass |
|
||||
| `csidrivers` | | storage.k8s.io | false | CSIDriver |
|
||||
| `csinodes` | | storage.k8s.io | false | CSINode |
|
||||
| `storageclasses` | `sc` | storage.k8s.io | false | StorageClass |
|
||||
| `volumeattachments` | | storage.k8s.io | false | VolumeAttachment |
|
||||
|
||||
## Output options
|
||||
|
||||
Use the following sections for information about how you can format or sort the output of certain commands. For details about which commands support the various output options, see the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation.
|
||||
|
||||
### Formatting output
|
||||
|
||||
The default output format for all `kubectl` commands is the human readable plain-text format. To output details to your terminal window in a specific format, you can add either the `-o` or `--output` flags to a supported `kubectl` command.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] -o <output_format>
|
||||
```
|
||||
|
||||
Depending on the `kubectl` operation, the following output formats are supported:
|
||||
|
||||
Output format | Description
|
||||
--------------| -----------
|
||||
`-o custom-columns=<spec>` | Print a table using a comma separated list of [custom columns](#custom-columns).
|
||||
`-o custom-columns-file=<filename>` | Print a table using the [custom columns](#custom-columns) template in the `<filename>` file.
|
||||
`-o json` | Output a JSON formatted API object.
|
||||
`-o jsonpath=<template>` | Print the fields defined in a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
|
||||
`-o jsonpath-file=<filename>` | Print the fields defined by the [jsonpath](/docs/reference/kubectl/jsonpath/) expression in the `<filename>` file.
|
||||
`-o name` | Print only the resource name and nothing else.
|
||||
`-o wide` | Output in the plain-text format with any additional information. For pods, the node name is included.
|
||||
`-o yaml` | Output a YAML formatted API object.
|
||||
|
||||
##### Example
|
||||
|
||||
In this example, the following command outputs the details for a single pod as a YAML formatted object:
|
||||
|
||||
```shell
|
||||
kubectl get pod web-pod-13je7 -o yaml
|
||||
```
|
||||
|
||||
Remember: See the [kubectl](/docs/reference/kubectl/kubectl/) reference documentation
|
||||
for details about which output format is supported by each command.
|
||||
|
||||
#### Custom columns
|
||||
|
||||
To define custom columns and output only the details that you want into a table, you can use the `custom-columns` option.
|
||||
You can choose to define the custom columns inline or use a template file: `-o custom-columns=<spec>` or `-o custom-columns-file=<filename>`.
|
||||
|
||||
##### Examples
|
||||
|
||||
Inline:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> -o custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion
|
||||
```
|
||||
|
||||
Template file:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> -o custom-columns-file=template.txt
|
||||
```
|
||||
|
||||
where the `template.txt` file contains:
|
||||
|
||||
```
|
||||
NAME RSRC
|
||||
metadata.name metadata.resourceVersion
|
||||
```
|
||||
The result of running either command is similar to:
|
||||
|
||||
```
|
||||
NAME RSRC
|
||||
submit-queue 610995
|
||||
```
|
||||
|
||||
#### Server-side columns
|
||||
|
||||
`kubectl` supports receiving specific column information from the server about objects.
|
||||
This means that for any given resource, the server will return columns and rows relevant to that resource, for the client to print.
|
||||
This allows for consistent human-readable output across clients used against the same cluster, by having the server encapsulate the details of printing.
|
||||
|
||||
This feature is enabled by default. To disable it, add the
|
||||
`--server-print=false` flag to the `kubectl get` command.
|
||||
|
||||
##### Examples
|
||||
|
||||
To print information about the status of a pod, use a command like the following:
|
||||
|
||||
```shell
|
||||
kubectl get pods <pod-name> --server-print=false
|
||||
```
|
||||
|
||||
The output is similar to:
|
||||
|
||||
```
|
||||
NAME AGE
|
||||
pod-name 1m
|
||||
```
|
||||
|
||||
### Sorting list objects
|
||||
|
||||
To output objects to a sorted list in your terminal window, you can add the `--sort-by` flag to a supported `kubectl` command. Sort your objects by specifying any numeric or string field with the `--sort-by` flag. To specify a field, use a [jsonpath](/docs/reference/kubectl/jsonpath/) expression.
|
||||
|
||||
#### Syntax
|
||||
|
||||
```shell
|
||||
kubectl [command] [TYPE] [NAME] --sort-by=<jsonpath_exp>
|
||||
```
|
||||
|
||||
##### Example
|
||||
|
||||
To print a list of pods sorted by name, you run:
|
||||
|
||||
```shell
|
||||
kubectl get pods --sort-by=.metadata.name
|
||||
```
|
||||
|
||||
## Examples: Common operations
|
||||
|
||||
Use the following set of examples to help you familiarize yourself with running the commonly used `kubectl` operations:
|
||||
|
||||
`kubectl apply` - Apply or Update a resource from a file or stdin.
|
||||
|
||||
```shell
|
||||
# Create a service using the definition in example-service.yaml.
|
||||
kubectl apply -f example-service.yaml
|
||||
|
||||
# Create a replication controller using the definition in example-controller.yaml.
|
||||
kubectl apply -f example-controller.yaml
|
||||
|
||||
# Create the objects that are defined in any .yaml, .yml, or .json file within the <directory> directory.
|
||||
kubectl apply -f <directory>
|
||||
```
|
||||
|
||||
`kubectl get` - List one or more resources.
|
||||
|
||||
```shell
|
||||
# List all pods in plain-text output format.
|
||||
kubectl get pods
|
||||
|
||||
# List all pods in plain-text output format and include additional information (such as node name).
|
||||
kubectl get pods -o wide
|
||||
|
||||
# List the replication controller with the specified name in plain-text output format. Tip: You can shorten and replace the 'replicationcontroller' resource type with the alias 'rc'.
|
||||
kubectl get replicationcontroller <rc-name>
|
||||
|
||||
# List all replication controllers and services together in plain-text output format.
|
||||
kubectl get rc,services
|
||||
|
||||
# List all daemon sets in plain-text output format.
|
||||
kubectl get ds
|
||||
|
||||
# List all pods running on node server01
|
||||
kubectl get pods --field-selector=spec.nodeName=server01
|
||||
```
|
||||
|
||||
`kubectl describe` - Display detailed state of one or more resources, including the uninitialized ones by default.
|
||||
|
||||
```shell
|
||||
# Display the details of the node with name <node-name>.
|
||||
kubectl describe nodes <node-name>
|
||||
|
||||
# Display the details of the pod with name <pod-name>.
|
||||
kubectl describe pods/<pod-name>
|
||||
|
||||
# Display the details of all the pods that are managed by the replication controller named <rc-name>.
|
||||
# Remember: Any pods that are created by the replication controller get prefixed with the name of the replication controller.
|
||||
kubectl describe pods <rc-name>
|
||||
|
||||
# Describe all pods
|
||||
kubectl describe pods
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
The `kubectl get` command is usually used for retrieving one or more
|
||||
resources of the same resource type. It features a rich set of flags that allows
|
||||
you to customize the output format using the `-o` or `--output` flag, for example.
|
||||
You can specify the `-w` or `--watch` flag to start watching updates to a particular
|
||||
object. The `kubectl describe` command is more focused on describing the many
|
||||
related aspects of a specified resource. It may invoke several API calls to the
|
||||
API server to build a view for the user. For example, the `kubectl describe node`
|
||||
command retrieves not only the information about the node, but also a summary of
|
||||
the pods running on it, the events generated for the node etc.
|
||||
{{< /note >}}
|
||||
|
||||
`kubectl delete` - Delete resources either from a file, stdin, or specifying label selectors, names, resource selectors, or resources.
|
||||
|
||||
```shell
|
||||
# Delete a pod using the type and name specified in the pod.yaml file.
|
||||
kubectl delete -f pod.yaml
|
||||
|
||||
# Delete all the pods and services that have the label '<label-key>=<label-value>'.
|
||||
kubectl delete pods,services -l <label-key>=<label-value>
|
||||
|
||||
# Delete all pods, including uninitialized ones.
|
||||
kubectl delete pods --all
|
||||
```
|
||||
|
||||
`kubectl exec` - Execute a command against a container in a pod.
|
||||
|
||||
```shell
|
||||
# Get output from running 'date' from pod <pod-name>. By default, output is from the first container.
|
||||
kubectl exec <pod-name> -- date
|
||||
|
||||
# Get output from running 'date' in container <container-name> of pod <pod-name>.
|
||||
kubectl exec <pod-name> -c <container-name> -- date
|
||||
|
||||
# Get an interactive TTY and run /bin/bash from pod <pod-name>. By default, output is from the first container.
|
||||
kubectl exec -ti <pod-name> -- /bin/bash
|
||||
```
|
||||
|
||||
`kubectl logs` - Print the logs for a container in a pod.
|
||||
|
||||
```shell
|
||||
# Return a snapshot of the logs from pod <pod-name>.
|
||||
kubectl logs <pod-name>
|
||||
|
||||
# Start streaming the logs from pod <pod-name>. This is similar to the 'tail -f' Linux command.
|
||||
kubectl logs -f <pod-name>
|
||||
```
|
||||
|
||||
`kubectl diff` - View a diff of the proposed updates to a cluster.
|
||||
|
||||
```shell
|
||||
# Diff resources included in "pod.json".
|
||||
kubectl diff -f pod.json
|
||||
|
||||
# Diff file read from stdin.
|
||||
cat service.yaml | kubectl diff -f -
|
||||
```
|
||||
|
||||
## Examples: Creating and using plugins
|
||||
|
||||
Use the following set of examples to help you familiarize yourself with writing and using `kubectl` plugins:
|
||||
|
||||
```shell
|
||||
# create a simple plugin in any language and name the resulting executable file
|
||||
# so that it begins with the prefix "kubectl-"
|
||||
cat ./kubectl-hello
|
||||
```
|
||||
```shell
|
||||
#!/bin/sh
|
||||
|
||||
# this plugin prints the words "hello world"
|
||||
echo "hello world"
|
||||
```
|
||||
With a plugin written, let's make it executable:
|
||||
```bash
|
||||
chmod a+x ./kubectl-hello
|
||||
|
||||
# and move it to a location in our PATH
|
||||
sudo mv ./kubectl-hello /usr/local/bin
|
||||
sudo chown root:root /usr/local/bin
|
||||
|
||||
# You have now created and "installed" a kubectl plugin.
|
||||
# You can begin using this plugin by invoking it from kubectl as if it were a regular command
|
||||
kubectl hello
|
||||
```
|
||||
```
|
||||
hello world
|
||||
```
|
||||
|
||||
```shell
|
||||
# You can "uninstall" a plugin, by removing it from the folder in your
|
||||
# $PATH where you placed it
|
||||
sudo rm /usr/local/bin/kubectl-hello
|
||||
```
|
||||
|
||||
In order to view all of the plugins that are available to `kubectl`, use
|
||||
the `kubectl plugin list` subcommand:
|
||||
|
||||
```shell
|
||||
kubectl plugin list
|
||||
```
|
||||
The output is similar to:
|
||||
```
|
||||
The following kubectl-compatible plugins are available:
|
||||
|
||||
/usr/local/bin/kubectl-hello
|
||||
/usr/local/bin/kubectl-foo
|
||||
/usr/local/bin/kubectl-bar
|
||||
```
|
||||
|
||||
`kubectl plugin list` also warns you about plugins that are not
|
||||
executable, or that are shadowed by other plugins; for example:
|
||||
```shell
|
||||
sudo chmod -x /usr/local/bin/kubectl-foo # remove execute permission
|
||||
kubectl plugin list
|
||||
```
|
||||
```
|
||||
The following kubectl-compatible plugins are available:
|
||||
|
||||
/usr/local/bin/kubectl-hello
|
||||
/usr/local/bin/kubectl-foo
|
||||
- warning: /usr/local/bin/kubectl-foo identified as a plugin, but it is not executable
|
||||
/usr/local/bin/kubectl-bar
|
||||
|
||||
error: one plugin warning was found
|
||||
```
|
||||
|
||||
You can think of plugins as a means to build more complex functionality on top
|
||||
of the existing kubectl commands:
|
||||
|
||||
```shell
|
||||
cat ./kubectl-whoami
|
||||
```
|
||||
The next few examples assume that you already made `kubectl-whoami` have
|
||||
the following contents:
|
||||
```shell
|
||||
#!/bin/bash
|
||||
|
||||
# this plugin makes use of the `kubectl config` command in order to output
|
||||
# information about the current user, based on the currently selected context
|
||||
kubectl config view --template='{{ range .contexts }}{{ if eq .name "'$(kubectl config current-context)'" }}Current user: {{ printf "%s\n" .context.user }}{{ end }}{{ end }}'
|
||||
```
|
||||
|
||||
Running the above command gives you an output containing the user for the
|
||||
current context in your KUBECONFIG file:
|
||||
|
||||
```shell
|
||||
# make the file executable
|
||||
sudo chmod +x ./kubectl-whoami
|
||||
|
||||
# and move it into your PATH
|
||||
sudo mv ./kubectl-whoami /usr/local/bin
|
||||
|
||||
kubectl whoami
|
||||
Current user: plugins-user
|
||||
```
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
* Start using the [kubectl](/docs/reference/generated/kubectl/kubectl-commands/) commands.
|
||||
|
||||
* To find out more about plugins, take a look at the [example cli plugin](https://github.com/kubernetes/sample-cli-plugin).
|
||||
|
||||
+10
-1
@@ -2,6 +2,7 @@
|
||||
title: Well-Known Labels, Annotations and Taints
|
||||
content_type: concept
|
||||
weight: 20
|
||||
no_list: true
|
||||
---
|
||||
|
||||
<!-- overview -->
|
||||
@@ -12,7 +13,7 @@ This document serves both as a reference to the values and as a coordination poi
|
||||
|
||||
<!-- body -->
|
||||
|
||||
## Core
|
||||
## Labels, annotations and taints used on API objects
|
||||
|
||||
### kubernetes.io/arch
|
||||
|
||||
@@ -482,6 +483,14 @@ you through the steps you follow to apply a seccomp profile to a Pod or to one o
|
||||
its containers. That tutorial covers the supported mechanism for configuring seccomp in Kubernetes,
|
||||
based on setting `securityContext` within the Pod's `.spec`.
|
||||
|
||||
## Annotations used for audit
|
||||
|
||||
- [`pod-security.kubernetes.io/exempt`](/docs/reference/labels-annotations-taints/audit-annotations/#pod-security-kubernetes-io-exempt)
|
||||
- [`pod-security.kubernetes.io/enforce-policy`](/docs/reference/labels-annotations-taints/audit-annotations/#pod-security-kubernetes-io-enforce-policy)
|
||||
- [`pod-security.kubernetes.io/audit-violations`](/docs/reference/labels-annotations-taints/audit-annotations/#pod-security-kubernetes-io-audit-violations)
|
||||
|
||||
See more details on the [Audit Annotations](/docs/reference/labels-annotations-taints/audit-annotations/) page.
|
||||
|
||||
## kubeadm
|
||||
|
||||
### kubeadm.alpha.kubernetes.io/cri-socket
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
title: "Audit Annotations"
|
||||
weight: 1
|
||||
---
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
This page serves as a reference for the audit annotations of the kubernetes.io
|
||||
namespace. These annotations apply to `Event` object from API group
|
||||
`audit.k8s.io`.
|
||||
|
||||
{{< note >}}
|
||||
The following annotations are not used within the Kubernetes API. When you
|
||||
[enable auditing](/docs/tasks/debug-application-cluster/audit/) in your cluster,
|
||||
audit event data is written using `Event` from API group `audit.k8s.io`.
|
||||
The annotations apply to audit events. Audit events are different from objects in the
|
||||
[Event API](/docs/reference/kubernetes-api/cluster-resources/event-v1/) (API group
|
||||
`events.k8s.io`).
|
||||
{{< /note >}}
|
||||
|
||||
<!-- body -->
|
||||
|
||||
## pod-security.kubernetes.io/exempt
|
||||
|
||||
Example: `pod-security.kubernetes.io/exempt: namespace`
|
||||
|
||||
Value **must** be one of `user`, `namespace`, or `runtimeClass` which correspond to
|
||||
[Pod Security Exemption](/docs/concepts/security/pod-security-admission/#exemptions)
|
||||
dimensions. This annotation indicates on which dimension was based the exemption
|
||||
from the PodSecurity enforcement.
|
||||
|
||||
|
||||
## pod-security.kubernetes.io/enforce-policy
|
||||
|
||||
Example: `pod-security.kubernetes.io/enforce-policy: restricted:latest`
|
||||
|
||||
Value **must** be `privileged:<version>`, `baseline:<version>`,
|
||||
`restricted:<version>` which correspond to [Pod Security
|
||||
Standard](/docs/concepts/security/pod-security-standards) levels accompanied by
|
||||
a version which **must** be `latest` or a valid Kubernetes version in the format
|
||||
`v<MAJOR>.<MINOR>`. This annotations informs about the enforcement level that
|
||||
allowed or denied the pod during PodSecurity admission.
|
||||
|
||||
See [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
|
||||
for more information.
|
||||
|
||||
## pod-security.kubernetes.io/audit-violations
|
||||
|
||||
Example: `pod-security.kubernetes.io/audit-violations: would violate
|
||||
PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container
|
||||
"example" must set securityContext.allowPrivilegeEscalation=false), ...`
|
||||
|
||||
Value details an audit policy violation, it contains the
|
||||
[Pod Security Standard](/docs/concepts/security/pod-security-standards/) level
|
||||
that was transgressed as well as the specific policies on the fields that were
|
||||
violated from the PodSecurity enforcement.
|
||||
|
||||
See [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
|
||||
for more information.
|
||||
@@ -85,7 +85,7 @@ might have to add an equivalent field or represent it as an annotation.
|
||||
* **Beta API versions must be supported for 9 months or 3 releases (whichever is longer) after deprecation**
|
||||
* **Alpha API versions may be removed in any release without prior deprecation notice**
|
||||
|
||||
This ensures beta API support covers the [maximum supported version skew of 2 releases](/docs/setup/release/version-skew-policy/).
|
||||
This ensures beta API support covers the [maximum supported version skew of 2 releases](/releases/version-skew-policy/).
|
||||
|
||||
{{< note >}}
|
||||
There are no current plans for a major version revision of Kubernetes that removes GA APIs.
|
||||
|
||||
@@ -231,7 +231,7 @@ See the [list of add-ons](/docs/concepts/cluster-administration/addons/) to expl
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
* Learn more about Kubernetes [concepts](/docs/concepts/) and [`kubectl`](/docs/reference/kubectl/overview/).
|
||||
* Learn more about Kubernetes [concepts](/docs/concepts/) and [`kubectl`](/docs/reference/kubectl/).
|
||||
* Learn more about `kops` [advanced usage](https://kops.sigs.k8s.io/) for tutorials, best practices and advanced configuration options.
|
||||
* Follow `kops` community discussions on Slack: [community discussions](https://github.com/kubernetes/kops#other-ways-to-communicate-with-the-contributors)
|
||||
* Contribute to `kops` by addressing or raising an issue [GitHub Issues](https://github.com/kubernetes/kops/issues)
|
||||
|
||||
+10
-1
@@ -283,6 +283,15 @@ If your network is not working or CoreDNS is not in the `Running` state, check o
|
||||
[troubleshooting guide](/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/)
|
||||
for `kubeadm`.
|
||||
|
||||
### Managed node labels
|
||||
|
||||
By default, kubeadm enables the [NodeRestriction](/docs/reference/access-authn-authz/admission-controllers/#noderestriction)
|
||||
admission controller that restricts what labels can be self-applied by kubelets on node registration.
|
||||
The admission controller documentation covers what labels are permitted to be used with the kubelet `--node-labels` option.
|
||||
The `node-role.kubernetes.io/control-plane` label is such a restricted label and kubeadm manually applies it using
|
||||
a privileged client after a node has been created. To do that manually you can do the same by using `kubectl label`
|
||||
and ensure it is using a privileged kubeconfig such as the kubeadm managed `/etc/kubernetes/admin.conf`.
|
||||
|
||||
### Control plane node isolation
|
||||
|
||||
By default, your cluster will not schedule Pods on the control plane nodes for security
|
||||
@@ -494,7 +503,7 @@ options.
|
||||
* <a id="lifecycle" />See [Upgrading kubeadm clusters](/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/)
|
||||
for details about upgrading your cluster using `kubeadm`.
|
||||
* Learn about advanced `kubeadm` usage in the [kubeadm reference documentation](/docs/reference/setup-tools/kubeadm/kubeadm)
|
||||
* Learn more about Kubernetes [concepts](/docs/concepts/) and [`kubectl`](/docs/reference/kubectl/overview/).
|
||||
* Learn more about Kubernetes [concepts](/docs/concepts/) and [`kubectl`](/docs/reference/kubectl/).
|
||||
* See the [Cluster Networking](/docs/concepts/cluster-administration/networking/) page for a bigger list
|
||||
of Pod network add-ons.
|
||||
* <a id="other-addons" />See the [list of add-ons](/docs/concepts/cluster-administration/addons/) to
|
||||
|
||||
@@ -164,10 +164,15 @@ It augments the basic
|
||||
[`kubelet.service` for RPM](https://github.com/kubernetes/release/blob/master/cmd/kubepkg/templates/latest/rpm/kubelet/kubelet.service) or
|
||||
[`kubelet.service` for DEB](https://github.com/kubernetes/release/blob/master/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service):
|
||||
|
||||
{{< note >}}
|
||||
The contents below are just an example. If you don't want to use a package manager
|
||||
follow the guide outlined in the [Without a package manager](/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#k8s-install-2))
|
||||
section.
|
||||
{{< /note >}}
|
||||
|
||||
```none
|
||||
[Service]
|
||||
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf
|
||||
--kubeconfig=/etc/kubernetes/kubelet.conf"
|
||||
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
|
||||
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
|
||||
# This is a file that "kubeadm init" and "kubeadm join" generate at runtime, populating
|
||||
the KUBELET_KUBEADM_ARGS variable dynamically
|
||||
@@ -201,5 +206,3 @@ The DEB and RPM packages shipped with the Kubernetes releases are:
|
||||
| `kubelet` | Installs the kubelet binary in `/usr/bin` and CNI binaries in `/opt/cni/bin`. |
|
||||
| `kubectl` | Installs the `/usr/bin/kubectl` binary. |
|
||||
| `cri-tools` | Installs the `/usr/bin/crictl` binary from the [cri-tools git repository](https://github.com/kubernetes-sigs/cri-tools). |
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -267,8 +267,8 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
|
||||
|
||||
```sh
|
||||
root@HOST0 $ kubeadm init phase etcd local --config=/tmp/${HOST0}/kubeadmcfg.yaml
|
||||
root@HOST1 $ kubeadm init phase etcd local --config=/tmp/${HOST1}/kubeadmcfg.yaml
|
||||
root@HOST2 $ kubeadm init phase etcd local --config=/tmp/${HOST2}/kubeadmcfg.yaml
|
||||
root@HOST1 $ kubeadm init phase etcd local --config=$HOME/kubeadmcfg.yaml
|
||||
root@HOST2 $ kubeadm init phase etcd local --config=$HOME/kubeadmcfg.yaml
|
||||
```
|
||||
|
||||
1. Optional: Check the cluster health
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ This guide walks you through the steps to configure and deploy a Windows contain
|
||||
control plane and a [worker node running Windows Server](/docs/tasks/administer-cluster/kubeadm/adding-windows-nodes/)
|
||||
* It is important to note that creating and deploying services and workloads on Kubernetes
|
||||
behaves in much the same way for Linux and Windows containers.
|
||||
[Kubectl commands](/docs/reference/kubectl/overview/) to interface with the cluster are identical.
|
||||
[Kubectl commands](/docs/reference/kubectl/) to interface with the cluster are identical.
|
||||
The example in the section below is provided to jumpstart your experience with Windows containers.
|
||||
|
||||
## Getting Started: Deploying a Windows container
|
||||
|
||||
@@ -27,8 +27,8 @@ kubectl config view
|
||||
```
|
||||
|
||||
Many of the [examples](/docs/reference/kubectl/cheatsheet/) provide an introduction to using
|
||||
kubectl and complete documentation is found in the
|
||||
[kubectl manual](/docs/reference/kubectl/overview/).
|
||||
`kubectl`, and complete documentation is found in the
|
||||
[kubectl reference](/docs/reference/kubectl/).
|
||||
|
||||
## Directly accessing the REST API
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ kubectl config view
|
||||
```
|
||||
|
||||
Many of the [examples](https://github.com/kubernetes/examples/tree/master/) provide an introduction to using
|
||||
kubectl. Complete documentation is found in the [kubectl manual](/docs/reference/kubectl/overview/).
|
||||
kubectl. Complete documentation is found in the [kubectl manual](/docs/reference/kubectl/).
|
||||
|
||||
### Directly accessing the REST API
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ first drain the node (or nodes) that you are upgrading. In the case of control p
|
||||
they could be running CoreDNS Pods or other critical workloads. For more information see
|
||||
[Draining nodes](/docs/tasks/administer-cluster/safely-drain-node/).
|
||||
- All containers are restarted after upgrade, because the container spec hash value is changed.
|
||||
- To verify that the kubelet service has successfully restarted after the kubelet has been upgraded, you can execute `systemctl status kubelet` or view the service logs with `journalctl -xeu kubelet`.
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
|
||||
@@ -49,6 +49,24 @@ Rootless Podman is not supported.
|
||||
|
||||
<!-- Supporting rootless podman is discussed in https://github.com/kubernetes/minikube/issues/8719 -->
|
||||
|
||||
## Running Kubernetes inside Unprivileged Containers
|
||||
|
||||
{{% thirdparty-content %}}
|
||||
|
||||
### sysbox
|
||||
|
||||
[Sysbox](https://github.com/nestybox/sysbox) is an open-source container runtime
|
||||
(similar to "runc") that supports running system-level workloads such as Docker
|
||||
and Kubernetes inside unprivileged containers isolated with the Linux user
|
||||
namespace.
|
||||
|
||||
See [Sysbox Quick Start Guide: Kubernetes-in-Docker](https://github.com/nestybox/sysbox/blob/master/docs/quickstart/kind.md) for more info.
|
||||
|
||||
Sysbox supports running Kubernetes inside unprivileged containers without
|
||||
requiring Cgroup v2 and without the `KubeletInUserNamespace` feature gate. It
|
||||
does this by exposing specially crafted `/proc` and `/sys` filesystems inside
|
||||
the container plus several other advanced OS virtualization techniques.
|
||||
|
||||
## Running Rootless Kubernetes directly on a host
|
||||
|
||||
{{% thirdparty-content %}}
|
||||
@@ -235,7 +253,7 @@ This feature gate also allows kube-proxy to ignore an error during setting `RLIM
|
||||
The `KubeletInUserNamespace` feature gate was introduced in Kubernetes v1.22 with "alpha" status.
|
||||
|
||||
Running kubelet in a user namespace without using this feature gate is also possible
|
||||
by mounting a specially crafted proc filesystem, but not officially supported.
|
||||
by mounting a specially crafted proc filesystem (as done by [Sysbox](https://github.com/nestybox/sysbox)), but not officially supported.
|
||||
|
||||
### Configuring kube-proxy
|
||||
|
||||
@@ -272,4 +290,3 @@ on the rootlesscontaine.rs website.
|
||||
- [Usernetes](https://github.com/rootless-containers/usernetes)
|
||||
- [Running K3s with rootless mode](https://rancher.com/docs/k3s/latest/en/advanced/#running-k3s-with-rootless-mode-experimental)
|
||||
- [KEP-2033: Kubelet-in-UserNS (aka Rootless mode)](https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2033-kubelet-in-userns-aka-rootless)
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ Historically, Kubernetes was written to work specifically with Docker Engine.
|
||||
Kubernetes took care of networking and scheduling, relying on Docker Engine for launching
|
||||
and running containers (within Pods) on a node. Some information that is relevant to telemetry,
|
||||
such as a pod name, is only available from Kubernetes components. Other data, such as container
|
||||
metrics, is not the responsibility of the container runtime. Early yelemetry agents needed to query the
|
||||
metrics, is not the responsibility of the container runtime. Early telemetry agents needed to query the
|
||||
container runtime **and** Kubernetes to report an accurate picture. Over time, Kubernetes gained
|
||||
the ability to support multiple runtimes, and now supports any runtime that is compatible with
|
||||
the container runtime interface.
|
||||
|
||||
@@ -91,7 +91,7 @@ flag.
|
||||
It is recommended that the kubernetes system daemons are placed under a top
|
||||
level control group (`runtime.slice` on systemd machines for example). Each
|
||||
system daemon should ideally run within its own child control group. Refer to
|
||||
[the design proposal](https://git.k8s.io/community/contributors/design-proposals/node/node-allocatable.md#recommended-cgroups-setup)
|
||||
[the design proposal](https://git.k8s.io/design-proposals-archive/node/node-allocatable.md#recommended-cgroups-setup)
|
||||
for more details on recommended control group hierarchy.
|
||||
|
||||
Note that Kubelet **does not** create `--kube-reserved-cgroup` if it doesn't
|
||||
|
||||
@@ -23,8 +23,6 @@ This task also assumes that you have met the following prerequisites:
|
||||
and have [configured PodDisruptionBudgets](/docs/tasks/run-application/configure-pdb/) for
|
||||
applications that need them.
|
||||
|
||||
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
## (Optional) Configure a disruption budget {#configure-poddisruptionbudget}
|
||||
@@ -100,95 +98,12 @@ replicas to fall below the specified budget are blocked.
|
||||
|
||||
If you prefer not to use [kubectl drain](/docs/reference/generated/kubectl/kubectl-commands/#drain) (such as
|
||||
to avoid calling to an external command, or to get finer control over the pod
|
||||
eviction process), you can also programmatically cause evictions using the eviction API.
|
||||
eviction process), you can also programmatically cause evictions using the
|
||||
eviction API.
|
||||
|
||||
You should first be familiar with using [Kubernetes language clients](/docs/tasks/administer-cluster/access-cluster-api/#programmatic-access-to-the-api) to access the API.
|
||||
|
||||
The eviction subresource of a
|
||||
Pod can be thought of as a kind of policy-controlled DELETE operation on the Pod
|
||||
itself. To attempt an eviction (more precisely: to attempt to
|
||||
*create* an Eviction), you POST an attempted operation. Here's an example:
|
||||
|
||||
{{< tabs name="Eviction_example" >}}
|
||||
{{% tab name="policy/v1" %}}
|
||||
{{< note >}}
|
||||
`policy/v1` Eviction is available in v1.22+. Use `policy/v1beta1` with prior releases.
|
||||
{{< /note >}}
|
||||
|
||||
```json
|
||||
{
|
||||
"apiVersion": "policy/v1",
|
||||
"kind": "Eviction",
|
||||
"metadata": {
|
||||
"name": "quux",
|
||||
"namespace": "default"
|
||||
}
|
||||
}
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{% tab name="policy/v1beta1" %}}
|
||||
{{< note >}}
|
||||
Deprecated in v1.22 in favor of `policy/v1`
|
||||
{{< /note >}}
|
||||
|
||||
```json
|
||||
{
|
||||
"apiVersion": "policy/v1beta1",
|
||||
"kind": "Eviction",
|
||||
"metadata": {
|
||||
"name": "quux",
|
||||
"namespace": "default"
|
||||
}
|
||||
}
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{< /tabs >}}
|
||||
|
||||
You can attempt an eviction using `curl`:
|
||||
|
||||
```bash
|
||||
curl -v -H 'Content-type: application/json' https://your-cluster-api-endpoint.example/api/v1/namespaces/default/pods/quux/eviction -d @eviction.json
|
||||
```
|
||||
|
||||
The API can respond in one of three ways:
|
||||
|
||||
- If the eviction is granted, then the Pod is deleted as if you sent
|
||||
a `DELETE` request to the Pod's URL and received back `200 OK`.
|
||||
- If the current state of affairs wouldn't allow an eviction by the rules set
|
||||
forth in the budget, you get back `429 Too Many Requests`. This is
|
||||
typically used for generic rate limiting of *any* requests, but here we mean
|
||||
that this request isn't allowed *right now* but it may be allowed later.
|
||||
- If there is some kind of misconfiguration; for example multiple PodDisruptionBudgets
|
||||
that refer the same Pod, you get a `500 Internal Server Error` response.
|
||||
|
||||
For a given eviction request, there are two cases:
|
||||
|
||||
- There is no budget that matches this pod. In this case, the server always
|
||||
returns `200 OK`.
|
||||
- There is at least one budget. In this case, any of the three above responses may
|
||||
apply.
|
||||
|
||||
## Stuck evictions
|
||||
|
||||
In some cases, an application may reach a broken state, one where unless you intervene the
|
||||
eviction API will never return anything other than 429 or 500.
|
||||
|
||||
For example: this can happen if ReplicaSet is creating Pods for your application but
|
||||
the replacement Pods do not become `Ready`. You can also see similar symptoms if the
|
||||
last Pod evicted has a very long termination grace period.
|
||||
|
||||
In this case, there are two potential solutions:
|
||||
|
||||
- Abort or pause the automated operation. Investigate the reason for the stuck application,
|
||||
and restart the automation.
|
||||
- After a suitably long wait, `DELETE` the Pod from your cluster's control plane, instead
|
||||
of using the eviction API.
|
||||
|
||||
Kubernetes does not specify what the behavior should be in this case; it is up to the
|
||||
application owners and cluster owners to establish an agreement on behavior in these cases.
|
||||
For more information, see [API-initiated eviction](/docs/concepts/scheduling-eviction/api-eviction/).
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
* Follow steps to protect your application by [configuring a Pod Disruption Budget](/docs/tasks/run-application/configure-pdb/).
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ accomplish commonly used tasks, and [Tutorials](/docs/tutorials/) are more
|
||||
comprehensive walkthroughs of real-world, industry-specific, or end-to-end
|
||||
development scenarios. The [Reference](/docs/reference/) section provides
|
||||
detailed documentation on the [Kubernetes API](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)
|
||||
and command-line interfaces (CLIs), such as [`kubectl`](/docs/reference/kubectl/overview/).
|
||||
and command-line interfaces (CLIs), such as [`kubectl`](/docs/reference/kubectl/).
|
||||
|
||||
## Help! My question isn't covered! I need help now!
|
||||
|
||||
|
||||
+7
-7
@@ -725,7 +725,7 @@ For example:
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "self.minReplicas <= self.replicas"
|
||||
message: "replicas should be greater than or equal to minReplicas."
|
||||
- rule: "self.replicas <= self.maxReplicas"
|
||||
@@ -829,7 +829,7 @@ Xref: [Supported evaluation on CEL](https://github.com/google/cel-spec/blob/v0.6
|
||||
...
|
||||
openAPIV3Schema:
|
||||
type: object
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "self.status.availableReplicas >= self.spec.minReplicas"
|
||||
properties:
|
||||
spec:
|
||||
@@ -856,7 +856,7 @@ Xref: [Supported evaluation on CEL](https://github.com/google/cel-spec/blob/v0.6
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "has(self.foo)"
|
||||
properties:
|
||||
...
|
||||
@@ -874,7 +874,7 @@ Xref: [Supported evaluation on CEL](https://github.com/google/cel-spec/blob/v0.6
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "self['xyz'].foo > 0"
|
||||
additionalProperties:
|
||||
...
|
||||
@@ -894,7 +894,7 @@ Xref: [Supported evaluation on CEL](https://github.com/google/cel-spec/blob/v0.6
|
||||
...
|
||||
foo:
|
||||
type: array
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "size(self) == 1"
|
||||
items:
|
||||
type: string
|
||||
@@ -912,7 +912,7 @@ Xref: [Supported evaluation on CEL](https://github.com/google/cel-spec/blob/v0.6
|
||||
...
|
||||
foo:
|
||||
type: integer
|
||||
x-kubernetes-validation-rules:
|
||||
x-kubernetes-validations:
|
||||
- rule: "self > 0"
|
||||
```
|
||||
Examples:
|
||||
@@ -1125,7 +1125,7 @@ with `foo` pruned and defaulted because the field is non-nullable, `bar` maintai
|
||||
|
||||
CustomResourceDefinition [OpenAPI v3 validation schemas](#validation) which are [structural](#specifying-a-structural-schema) and [enable pruning](#field-pruning) are published as part of the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions) from Kubernetes API server.
|
||||
|
||||
The [kubectl](/docs/reference/kubectl/overview) command-line tool consumes the published schema to perform client-side validation (`kubectl create` and `kubectl apply`), schema explanation (`kubectl explain`) on custom resources. The published schema can be consumed for other purposes as well, like client generation or documentation.
|
||||
The [kubectl](/docs/reference/kubectl/) command-line tool consumes the published schema to perform client-side validation (`kubectl create` and `kubectl apply`), schema explanation (`kubectl explain`) on custom resources. The published schema can be consumed for other purposes as well, like client generation or documentation.
|
||||
|
||||
The OpenAPI v3 validation schema is converted to OpenAPI v2 schema, and
|
||||
show up in `definitions` and `paths` fields in the [OpenAPI v2 spec](/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions).
|
||||
|
||||
@@ -18,7 +18,7 @@ draft](https://github.com/ietf-wg-acme/acme/).
|
||||
|
||||
{{< note >}}
|
||||
Certificates created using the `certificates.k8s.io` API are signed by a
|
||||
dedicated CA. It is possible to configure your cluster to use the cluster root
|
||||
[dedicated CA](#a-note-to-cluster-administrators). It is possible to configure your cluster to use the cluster root
|
||||
CA for this purpose, but you should never rely on this. Do not assume that
|
||||
these certificates will validate against the cluster root CA.
|
||||
{{< /note >}}
|
||||
@@ -42,16 +42,25 @@ install it via your operating system's software sources, or fetch it from
|
||||
|
||||
## Trusting TLS in a cluster
|
||||
|
||||
Trusting the custom CA from an application running as a pod usually requires
|
||||
Trusting the [custom CA](#a-note-to-cluster-administrators) from an application running as a pod usually requires
|
||||
some extra application configuration. You will need to add the CA certificate
|
||||
bundle to the list of CA certificates that the TLS client or server trusts. For
|
||||
example, you would do this with a golang TLS config by parsing the certificate
|
||||
chain and adding the parsed certificates to the `RootCAs` field in the
|
||||
[`tls.Config`](https://godoc.org/crypto/tls#Config) struct.
|
||||
|
||||
You can distribute the CA certificate as a
|
||||
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap) that your
|
||||
pods have access to use.
|
||||
{{< note >}}
|
||||
Even though the custom CA certificate may be included in the filesystem (in the
|
||||
ConfigMap `kube-root-ca.crt`),
|
||||
you should not use that certificate authority for any purpose other than to verify internal
|
||||
Kubernetes endpoints. An example of an internal Kubernetes endpoint is the
|
||||
Service named `kubernetes` in the default namespace.
|
||||
|
||||
If you want to use a custom certificate authority for your workloads, you should generate
|
||||
that CA separately, and distribute its CA certificate using a
|
||||
[ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap) that your pods
|
||||
have access to read.
|
||||
{{< /note >}}
|
||||
|
||||
## Requesting a certificate
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ Pod runs a Container based on the provided Docker image.
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
For more information about `kubectl` commands, see the [kubectl overview](/docs/reference/kubectl/overview/).
|
||||
For more information about `kubectl` commands, see the [kubectl overview](/docs/reference/kubectl/).
|
||||
{{< /note >}}
|
||||
|
||||
## Create a Service
|
||||
|
||||
@@ -8,57 +8,63 @@ weight: 10
|
||||
This tutorial applies only for new clusters.
|
||||
{{% /alert %}}
|
||||
|
||||
Pod Security admission (PSA) is enabled by default in v1.23 and later, as it [graduated
|
||||
to beta](/blog/2021/12/09/pod-security-admission-beta/). Pod Security Admission
|
||||
Pod Security admission (PSA) is enabled by default in v1.23 and later, as it
|
||||
[graduated to beta](/blog/2021/12/09/pod-security-admission-beta/). Pod Security Admission
|
||||
is an admission controller that applies
|
||||
[Pod Security Standards](docs/concepts/security/pod-security-standards/)
|
||||
[Pod Security Standards](/docs/concepts/security/pod-security-standards/)
|
||||
when pods are created. In this tutorial, you will enforce the `baseline` Pod Security Standard,
|
||||
one namespace at a time.
|
||||
|
||||
You can also apply Pod Security Standards to multiple namespaces at once at the cluster
|
||||
level. For instructions, refer to [Apply Pod Security Standards at the cluster level](/docs/tutorials/security/cluster-level-pss).
|
||||
level. For instructions, refer to
|
||||
[Apply Pod Security Standards at the cluster level](/docs/tutorials/security/cluster-level-pss).
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
Install the following on your workstation:
|
||||
|
||||
- [KinD](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
|
||||
- [kubectl](https://kubernetes.io/docs/tasks/tools/)
|
||||
- [kubectl](/docs/tasks/tools/)
|
||||
|
||||
## Create cluster
|
||||
|
||||
1. Create a `KinD` cluster as follows:
|
||||
|
||||
```shell
|
||||
kind create cluster --name psa-ns-level --image kindest/node:v1.23.0
|
||||
```
|
||||
```shell
|
||||
kind create cluster --name psa-ns-level --image kindest/node:v1.23.0
|
||||
```
|
||||
|
||||
The output is similar to this:
|
||||
```
|
||||
Creating cluster "psa-ns-level" ...
|
||||
✓ Ensuring node image (kindest/node:v1.23.0) 🖼
|
||||
✓ Preparing nodes 📦
|
||||
✓ Writing configuration 📜
|
||||
✓ Starting control-plane 🕹️
|
||||
✓ Installing CNI 🔌
|
||||
✓ Installing StorageClass 💾
|
||||
Set kubectl context to "kind-psa-ns-level"
|
||||
You can now use your cluster with:
|
||||
|
||||
```
|
||||
Creating cluster "psa-ns-level" ...
|
||||
✓ Ensuring node image (kindest/node:v1.23.0) 🖼
|
||||
✓ Preparing nodes 📦
|
||||
✓ Writing configuration 📜
|
||||
✓ Starting control-plane 🕹️
|
||||
✓ Installing CNI 🔌
|
||||
✓ Installing StorageClass 💾
|
||||
Set kubectl context to "kind-psa-ns-level"
|
||||
You can now use your cluster with:
|
||||
|
||||
kubectl cluster-info --context kind-psa-ns-level
|
||||
kubectl cluster-info --context kind-psa-ns-level
|
||||
|
||||
Not sure what to do next? 😅 Check out https://kind.sigs.k8s.io/docs/user/quick-start/
|
||||
```
|
||||
Not sure what to do next? 😅 Check out https://kind.sigs.k8s.io/docs/user/quick-start/
|
||||
```
|
||||
|
||||
1. Set the kubectl context to the new cluster:
|
||||
```shell
|
||||
kubectl cluster-info --context kind-psa-ns-level
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl cluster-info --context kind-psa-ns-level
|
||||
```
|
||||
The output is similar to this:
|
||||
```
|
||||
Kubernetes control plane is running at https://127.0.0.1:50996
|
||||
CoreDNS is running at https://127.0.0.1:50996/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
|
||||
|
||||
```
|
||||
Kubernetes control plane is running at https://127.0.0.1:50996
|
||||
CoreDNS is running at https://127.0.0.1:50996/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
|
||||
|
||||
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
|
||||
```
|
||||
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
|
||||
```
|
||||
|
||||
## Create a namespace
|
||||
|
||||
@@ -67,7 +73,9 @@ Create a new namespace called `example`:
|
||||
```shell
|
||||
kubectl create ns example
|
||||
```
|
||||
|
||||
The output is similar to this:
|
||||
|
||||
```
|
||||
namespace/example created
|
||||
```
|
||||
@@ -78,63 +86,68 @@ namespace/example created
|
||||
built-in Pod Security Admission. In this step we will warn on baseline pod
|
||||
security standard as per the latest version (default value)
|
||||
|
||||
```shell
|
||||
kubectl label --overwrite ns example \
|
||||
```shell
|
||||
kubectl label --overwrite ns example \
|
||||
pod-security.kubernetes.io/warn=baseline \
|
||||
pod-security.kubernetes.io/warn-version=latest
|
||||
```
|
||||
```
|
||||
|
||||
2. Multiple pod security standards can be enabled on any namespace, using labels.
|
||||
Following command will `enforce` the `baseline` Pod Security Standard, but
|
||||
`warn` and `audit` for `restricted` Pod Security Standards as per the latest
|
||||
version (default value)
|
||||
|
||||
```
|
||||
kubectl label --overwrite ns example \
|
||||
pod-security.kubernetes.io/enforce=baseline \
|
||||
pod-security.kubernetes.io/enforce-version=latest \
|
||||
pod-security.kubernetes.io/warn=restricted \
|
||||
pod-security.kubernetes.io/warn-version=latest \
|
||||
pod-security.kubernetes.io/audit=restricted \
|
||||
pod-security.kubernetes.io/audit-version=latest
|
||||
```
|
||||
```shell
|
||||
kubectl label --overwrite ns example \
|
||||
pod-security.kubernetes.io/enforce=baseline \
|
||||
pod-security.kubernetes.io/enforce-version=latest \
|
||||
pod-security.kubernetes.io/warn=restricted \
|
||||
pod-security.kubernetes.io/warn-version=latest \
|
||||
pod-security.kubernetes.io/audit=restricted \
|
||||
pod-security.kubernetes.io/audit-version=latest
|
||||
```
|
||||
|
||||
## Verify the Pod Security Standards
|
||||
|
||||
1. Create a minimal pod in `example` namespace:
|
||||
|
||||
```shell
|
||||
cat <<EOF > /tmp/pss/nginx-pod.yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
EOF
|
||||
```
|
||||
```shell
|
||||
cat <<EOF > /tmp/pss/nginx-pod.yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
1. Apply the pod spec to the cluster in `example` namespace:
|
||||
```shell
|
||||
kubectl apply -n example -f /tmp/pss/nginx-pod.yaml
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl apply -n example -f /tmp/pss/nginx-pod.yaml
|
||||
```
|
||||
The output is similar to this:
|
||||
```
|
||||
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "nginx" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "nginx" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "nginx" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
|
||||
pod/nginx created
|
||||
```
|
||||
|
||||
```
|
||||
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "nginx" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "nginx" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "nginx" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
|
||||
pod/nginx created
|
||||
```
|
||||
|
||||
1. Apply the pod spec to the cluster in `default` namespace:
|
||||
```shell
|
||||
kubectl apply -n default -f /tmp/pss/nginx-pod.yaml
|
||||
```
|
||||
|
||||
```shell
|
||||
kubectl apply -n default -f /tmp/pss/nginx-pod.yaml
|
||||
```
|
||||
Output is similar to this:
|
||||
```
|
||||
pod/nginx created
|
||||
```
|
||||
|
||||
```
|
||||
pod/nginx created
|
||||
```
|
||||
|
||||
The Pod Security Standards were applied only to the `example`
|
||||
namespace. You could create the same Pod in the `default` namespace
|
||||
@@ -149,11 +162,13 @@ Run `kind delete cluster -name psa-ns-level` to delete the cluster created.
|
||||
- Run a
|
||||
[shell script](/examples/security/kind-with-namespace-level-baseline-pod-security.sh)
|
||||
to perform all the preceding steps all at once.
|
||||
|
||||
1. Create KinD cluster
|
||||
2. Create new namespace
|
||||
3. Apply `baseline` Pod Security Standard in `enforce` mode while applying
|
||||
`restricted` Pod Security Standard also in `warn` and `audit` mode.
|
||||
4. Create a new pod with the following pod security standards applied
|
||||
|
||||
- [Pod Security Admission](/docs/concepts/security/pod-security-admission/)
|
||||
- [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
|
||||
- [Apply Pod Security Standards at the cluster level](/docs/tutorials/security/cluster-level-pss/)
|
||||
- [Apply Pod Security Standards at the cluster level](/docs/tutorials/security/cluster-level-pss/)
|
||||
|
||||
Reference in New Issue
Block a user