kubernetes学习总结(14)——kubernetes实用命令总结(代码片段)

科技D人生 科技D人生     2023-03-03     520

关键词:

一、Pods

1、Get all pods in the current namespace

kubectl get pods

2、Get pods in all namespaces

kubectl get pods --all-namespaces

3、Get pods with more details

kubectl get pods -o wide

4、Get the yaml for a pod

kubectl get pod <pod> -o yaml

5、Inspect a pod

kubectl describe pods <pod>

6、Get pods sorted by a metric

kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'

7、Get pods with their labels

kubectl get pods --show-labels

8、Get pods that match a label

kubectl get pods -l <label>=<value>

9、Forward traffic from a localhost port to a pod port

kubectl port-forward <pod> <localhost-port>:<pod-port>

10、Run a command on a pod

kubectl exec <pod> -- <command>

11、Run a command on a container in a pod

kubectl exec <pod> -c <container> -- <command>

二、Secrets

1、Get all secrets in the current namespace

kubectl get secrets

2、Get secrets in all namespaces

kubectl get secrets --all-namespaces

3、Get secrets with more details

kubectl get secrets -o wide

4、Get the contents of a secret

kubectl get secrets <secret> -o yaml 

三、Services

1、Get all services in the current namespace

kubectl get services

2、Get services in all namespaces

kubectl get service --all-namespaces

3、Get services with more details

kubectl get service -o wide

4、Get the yaml for a services

kubectl get service <service> -o yaml

5、Inspect a service

kubectl describe service <service>

6、Get service's labels

kubectl get service --show-labels

7、Get services that match a label

kubectl get service -l <label>=<value>

四、Updating Resources

1、Roll a new version of a deployment

kubectl set image deployment/<deployment> <containername>=image:<version>

2、Check the deployment history

kubectl rollout history deployment/<deployment>

3、Rollback a deployment

kubectl rollout undo deployment/<deployment>

4、Rollback to a specific version

kubectl rollout undo deployment/<deployment> --to-revision=2

5、Watch a rolling update

kubectl rollout status -w deployment/<deployment>

6、Restart the rolling deploy

kubectl rollout restart deployment/<deployment>

7、Edit a resource’s yaml

kubectl edit deployment/<deployment>

8、Scale a deployment to 3 pods

kubectl scale --replicas=3 deployment/<deployment>

9、Delete a pod

kubectl delete pod <pod>

五、Context

1、Show contexts

kubectl config get-contexts

2、Show current context

kubectl config current-context

3、Switch context to another cluster

kubectl config use-context <my-cluster-name>

4、Change Namespace

kubectl config set-context --current --namespace=<namespace>

六、Logs

1、Show logs (stdout) of a pod

kubectl logs <pod>

2、Show logs (stdout) of pods that match a label

kubectl logs -l <label>=<value>

3、Show logs of a previous instantiation of a container

kubectl logs <pod> --previous

4、Show logs for a specific container in a pod (i.e. init container)

kubectl logs <pod> -c <container>

5、Following logs from a pod

kubectl logs -f <pod>

6、Follow all logs from a pod that match a label

kubectl logs -f -l <label>=<value> --all-containers

7、Show logs with verbosity level of logs from 0 - 9

kubectl logs <pod> --v=<0:9>

七、Deployments

1、Get all deployments in the current namespace

kubectl get deployment

2、Get deployments in all namespaces

kubectl get deployment --all-namespaces

3、Get deployments with more details

kubectl get deployment -o wide

4、Get the yaml for a deployment

kubectl get deployment <deployment> -o yaml

5、Inspect a deployment

kubectl describe deployment <deployment>

6、Get deployment's labels

kubectl get deployment --show-labels

7、Get deployments that match a label

kubectl get deployment -l <label>=<value>

八、Ingress

1、Get all ingress in the current namespace

kubectl get ingress

2、Get ingress in all namespaces

kubectl get ingress --all-namespaces

3、Get ingress with more details

kubectl get ingress -o wide

4、Get the yaml for a ingress

kubectl get ingress <ingress> -o yaml

5、Inspect a ingress

kubectl describe ingress <ingress>

6、Get ingress labels

kubectl get ingress --show-labels

7、Get ingress that match a label

kubectl get ingress -l <label>=<value>

九、Creating Resources

1、Create a kubernetes resource from a file

kubectl apply -f ./<manifest>.yaml

2、Create kubernetes resources from multiple files

kubectl apply -f ./<manifest>.yaml -f ./<manifest>.yaml

3、Create resources from all manifest files in a directory

kubectl apply -f ./<directory>

4、Create resource from a url

kubectl apply -f <url_to_manifest>

5、Start a single instance of an image

kubectl create deployment <deployment_name> --image=<image>

十、Nodes

1、Mark node as unschedulable

kubectl cordon <node>

2、Drain a node for maintenance

kubectl drain <node>

3、Mark node as schedulable

kubectl uncordon <node>

4、Show ‘top’ metrics for a node

kubectl top node <node>

5、Display addresses of the master and services

kubectl cluster-info

6、ump current cluster state to stdout

kubectl cluster-info dump

7、Show a list of eligible kube resource (i.e. pods, service, pv, etc)

kubectl api-resources

8、Show a list of eligible kube resources in your namespace

kubectl api-resources --namespaced=true

kubernetes学习总结-基本概念

...件  -doctor:负责本机的容器创建和管理工作3.Pod:  Kubernetes最基本概念  -Pause容器作为根容器,代表整个容器的ip和volume存储4.Label(标签):  -实现分组管理功能5.LabelSelector:  使用场景:  -监控Pod的副本数量,kube-Con... 查看详情

kubernetes学习总结synopsis

同类产品dockercompose、dockerswarm、dockermachine、mesos、marathonKubernetes项目地址https://github.com/kubernetes/kubernetes/releasesSchema?核心组件:1)APIserver:接收、分析用户请求,并处理用户请求2)Scheduler:调度资源(通过初选、优选、选定三个阶... 查看详情

kubernetes学习总结(28)——kubernetes常见问题总结(代码片段)

如何删除不一致状态下的rc、deployment、service在某些情况下经常发现kubectl进程挂起现象,然后在get时候发现删了一半而另外的删除不了[root@k8s-master ~]# kubectl get -f fluentd-elasticsearch/NAME DESIRED CURRENT READY AGErc/elasticsearch-logging-... 查看详情

kubernetes学习总结(18)——kubernetes容器网络

前言在Kubernetes 中要保证容器之间网络互通网络至关重要。Kubernetes 本身并没有实现容器网络而是通过插件化的方式自由接入,容器网络接入需要满足如下基本原则:pod无论运行在任何节点都可以互相直接通信,而不... 查看详情

kubernetes学习总结(29)——使用kubeadm部署kubernetes1.24详细步骤总结(代码片段)

前言kubeadm是Kubernetes官方提供的用于快速安部署Kubernetes集群的工具,伴随Kubernetes每个版本的发布都会同步更新,kubeadm会对集群配置方面的一些实践做调整,通过实验kubeadm可以学习到Kubernetes官方在集群配置上一些新... 查看详情

kubernetes学习总结(31)——kubernetes为何需要istio?

一、ServiceMesh是什么?“Aservicemeshisadedicatedinfrastructurelayerforhandlingservice-to-servicecommunication.“——WilliamMorgan。erviceMesh是一个专注于处理服务间通信的基础设施层。云原生应用有着复杂的服务拓扑,而ServiceMesh保证请求可以... 查看详情

kubernetes学习总结(31)——kubernetes为何需要istio?

一、ServiceMesh是什么?“Aservicemeshisadedicatedinfrastructurelayerforhandlingservice-to-servicecommunication.“——WilliamMorgan。erviceMesh是一个专注于处理服务间通信的基础设施层。云原生应用有着复杂的服务拓扑,而ServiceMesh保证请求可以... 查看详情

kubernetes学习总结(32)——kubernetes的架构原理简单总结

一、Master节点与 Node节点通讯原理Master节点启动时,会运行一个 kube-apiserver 进程,它提供了集群管理的API接口,是集群内各个功能模块之间数据交互和通信的中心枢纽,并且它页提供了完备的集群安全机制。在N... 查看详情

kubernetes学习总结(32)——kubernetes的架构原理简单总结

一、Master节点与 Node节点通讯原理Master节点启动时,会运行一个 kube-apiserver 进程,它提供了集群管理的API接口,是集群内各个功能模块之间数据交互和通信的中心枢纽,并且它页提供了完备的集群安全机制。在N... 查看详情

kubernetes学习总结(18)——kubernetes容器网络(代码片段)

前言在Kubernetes 中要保证容器之间网络互通网络至关重要。Kubernetes 本身并没有实现容器网络而是通过插件化的方式自由接入,容器网络接入需要满足如下基本原则:pod无论运行在任何节点都可以互相直接通信,而不... 查看详情

kubernetes学习14—dashboard搭建和认证(代码片段)

原文:kubernetes学习14—Dashboard搭建和认证本文收录在容器技术学习系列文章总目录一、介绍  KubernetesDashboard是Kubernetes集群的基于Web的通用UI。它允许用户管理在群集中运行的应用程序并对其进行故障排除,以及管理群集本身。&... 查看详情

kubernetes学习总结——kubernetes常见面试题汇总

简述etcd及其特点etcd是CoreOS团队发起的开源项目,是一个管理配置信息和服务发现(servicediscovery)的项目,它的目标是构建一个高可用的分布式键值(key-value)数据库,基于Go语言实现。特点:简单... 查看详情

kubernetes学习总结(26)——kubernetes网络模型基础指南(代码片段)

前言Kubernetes是为运行分布式集群而建立的,分布式系统的本质使得网络成为Kubernetes的核心和必要组成部分,了解Kubernetes网络模型可以使你能够正确运行、监控和排查应用程序故障。网络是非常复杂的,拥有许多概念... 查看详情

kubernetes学习总结(17)——kubernetes快速入门需要掌握的知识点总结(代码片段)

一、DockerDocker是基于操作系统的沙盒技术,使得用户更简单和完整的去打包自己的应用。docker底层是基于Linux的操作系统级别的虚拟化技术LXC实现;LXC是通过CGroup实现了虚拟化资源管理,用来保证应用资源的隔离和应... 查看详情

kubernetes学习总结(36)——kubernetes本地运行的四种方法(代码片段)

前言Kubernetes是一个开源的容器编排平台。它由Google开发,为自动化部署、扩展和管理容器化应用提供了一个开源系统。虽然大多数人在云环境中运行Kubernetes,但在本地运行Kubernetes集群不仅是可能的,它还至少有两个... 查看详情

kubernetes学习总结(36)——kubernetes本地运行的四种方法(代码片段)

前言Kubernetes是一个开源的容器编排平台。它由Google开发,为自动化部署、扩展和管理容器化应用提供了一个开源系统。虽然大多数人在云环境中运行Kubernetes,但在本地运行Kubernetes集群不仅是可能的,它还至少有两个... 查看详情

kubernetes学习总结(36)——kubernetes本地运行的四种方法(代码片段)

前言Kubernetes是一个开源的容器编排平台。它由Google开发,为自动化部署、扩展和管理容器化应用提供了一个开源系统。虽然大多数人在云环境中运行Kubernetes,但在本地运行Kubernetes集群不仅是可能的,它还至少有两个... 查看详情

kubernetes学习总结(27)——kubernetes安装redis集群的两个方案(代码片段)

一、自定义yaml文件安装背景在Kubernetes中部署Redis集群面临挑战,因为每个Redis实例都依赖于一个配置文件,该文件可以跟踪其他集群实例及其角色。为此,需要结合使用KubernetesStatefulSets和PersistentVolumes实现。Redis集群... 查看详情