代码拉取完成,页面将自动刷新
同步操作将从 turnon/linux-tutorial 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Kubernetes 是谷歌开源的容器集群管理系统 是用于自动部署,扩展和管理 Docker 应用程序的开源系统,简称 K8S。
关键词:
docker
K8S 主控组件(Master) 包含三个进程,都运行在集群中的某个节上,通常这个节点被称为 master 节点。这些进程包括:kube-apiserver
、kube-controller-manager
和 kube-scheduler
。
集群中的每个非 master 节点都运行两个进程:
Kubernetes 主要由以下几个核心组件组成:
K8S 包含若干抽象用来表示系统状态,包括:已部署的容器化应用和负载、与它们相关的网络和磁盘资源以及有关集群正在运行的其他操作的信息。
Pod
- K8S 使用 Pod 来管理容器,每个 Pod 可以包含一个或多个紧密关联的容器。Pod 是一组紧密关联的容器集合,它们共享 PID、IPC、Network 和 UTS namespace,是 K8S 调度的基本单位。Pod 内的多个容器共享网络和文件系统,可以通过进程间通信和文件共享这种简单高效的方式组合完成服务。Node
- Node 是 Pod 真正运行的主机,可以是物理机,也可以是虚拟机。为了管理 Pod,每个 Node 节点上至少要运行 container runtime(比如 docker 或者 rkt)、kubelet
和 kube-proxy
服务。Namespace
- Namespace 是对一组资源和对象的抽象集合,比如可以用来将系统内部的对象划分为不同的项目组或用户组。常见的 pods, services, replication controllers 和 deployments 等都是属于某一个 namespace 的(默认是 default),而 node, persistentVolumes 等则不属于任何 namespace。Service
- Service 是应用服务的抽象,通过 labels 为应用提供负载均衡和服务发现。匹配 labels 的 Pod IP 和端口列表组成 endpoints,由 kube-proxy 负责将服务 IP 负载均衡到这些 endpoints 上。每个 Service 都会自动分配一个 cluster IP(仅在集群内部可访问的虚拟地址)和 DNS 名,其他容器可以通过该地址或 DNS 来访问服务,而不需要了解后端容器的运行。Label
- Label 是识别 K8S 对象的标签,以 key/value 的方式附加到对象上(key 最长不能超过 63 字节,value 可以为空,也可以是不超过 253 字节的字符串)。Label 不提供唯一性,并且实际上经常是很多对象(如 Pods)都使用相同的 label 来标志具体的应用。Label 定义好后其他对象可以使用 Label Selector 来选择一组相同 label 的对象(比如 ReplicaSet 和 Service 用 label 来选择一组 Pod)。Label Selector 支持以下几种方式:
app=nginx
和 env!=production
env in (production, qa)
app=nginx,env=test
Annotations
- Annotations 是 key/value 形式附加于对象的注解。不同于 Labels 用于标志和选择对象,Annotations 则是用来记录一些附加信息,用来辅助应用部署、安全策略以及调度策略等。比如 deployment 使用 annotations 来记录 rolling update 的状态。# Setup autocomplete in bash; bash-completion package should be installed first
source <(kubectl completion bash)
# View Kubernetes config
kubectl config view
# View specific config items by json path
kubectl config view -o jsonpath='{.users[?(@.name == "k8s")].user.password}'
# Set credentials for foo.kuberntes.com
kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword
# List all services in the namespace
kubectl get services
# List all pods in all namespaces in wide format
kubectl get pods -o wide --all-namespaces
# List all pods in json (or yaml) format
kubectl get pods -o json
# Describe resource details (node, pod, svc)
kubectl describe nodes my-node
# List services sorted by name
kubectl get services --sort-by=.metadata.name
# List pods sorted by restart count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
# Rolling update pods for frontend-v1
kubectl rolling-update frontend-v1 -f frontend-v2.json
# Scale a replicaset named 'foo' to 3
kubectl scale --replicas=3 rs/foo
# Scale a resource specified in "foo.yaml" to 3
kubectl scale --replicas=3 -f foo.yaml
# Execute a command in every pod / replica
for i in 0 1; do kubectl exec foo-$i -- sh -c 'echo $(hostname) > /usr/share/nginx/html/index.html'; done
# Get documentation for pod or service
kubectl explain pods,svc
# Create resource(s) like pods, services or daemonsets
kubectl create -f ./my-manifest.yaml
# Apply a configuration to a resource
kubectl apply -f ./my-manifest.yaml
# Start a single instance of Nginx
kubectl run nginx --image=nginx
# Create a secret with several keys
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
password: $(echo "s33msi4" | base64)
username: $(echo "jane"| base64)
EOF
# Delete a resource
kubectl delete -f ./my-manifest.yaml
# Deploy Heapster from Github repository
kubectl create -f deploy/kube-config/standalone/
# Show metrics for nodes
kubectl top node
# Show metrics for pods
kubectl top pod
# Show metrics for a given pod and its containers
kubectl top pod pod_name --containers
# Dump pod logs (stdout)
kubectl logs pod_name
# Stream pod container logs (stdout, multi-container case)
kubectl logs -f pod_name -c my-container
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。