18.k8s官方文档

本文介绍如何使用Kubernetes的kubectl命令进行应用部署,包括创建Deployment、获取部署信息、节点资源分配等操作。同时,讲解了Service的概念,即如何在Pod间进行流量路由,确保应用程序即使在Pod实例变化时也能稳定运行。

kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080: The run command creates a new deployment. We need to provide the deployment name and app image location (include the full repository url for images hosted outside Docker hub). We want to run the app on a specific port so we add the --port parameter:

kubectl get deployments: To list your deployments

kubectl get nodes: Kubernetes will choose where to deploy our application based on Node available resources.

kubectl proxy: You can see all those APIs hosted through the proxy endpoint, now available at through http://localhost:8001. For example, we can query the version directly through the API using the curl command:

curl http://localhost:8001/version: The API server will automatically create an endpoint for each pod, based on the pod name, that is also accessible through the proxy.

export POD_NAME=$(kubectl get pods -o go-template --template ‘{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}’)
echo Name of the Pod: $POD_NAME : The API server will automatically create an endpoint for each pod, based on the pod name, that is also accessible through the proxy. First we need to get the Pod name, and we’ll store in the environment variable POD_NAME

curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/: Now we can make an HTTP request to the application running in that pod:

The Deployment instructs Kubernetes how to create and update instances of your application. Once you’ve created a Deployment, the Kubernetes master schedules mentioned application instances onto individual Nodes in the cluster.
在这里插入图片描述
A Service routes traffic across a set of Pods. Services are the abstraction that allow pods to die and replicate in Kubernetes without impacting your application. 在这里插入图片描述

error parsing calico.yaml: error converting YAML to JSON: yaml: line 206: mapping values are not allowed in this context Error from server (Forbidden): error when retrieving current configuration of: Resource: "policy/v1, Resource=poddisruptionbudgets", GroupVersionKind: "policy/v1, Kind=PodDisruptionBudget" Name: "calico-kube-controllers", Namespace: "kube-system" from server for: "calico.yaml": poddisruptionbudgets.policy "calico-kube-controllers" is forbidden: User "system:node:master" cannot get resource "poddisruptionbudgets" in API group "policy" in the namespace "kube-system" Error from server (Forbidden): error when retrieving current configuration of: Resource: "/v1, Resource=serviceaccounts", GroupVersionKind: "/v1, Kind=ServiceAccount" Name: "calico-kube-controllers", Namespace: "kube-system" from server for: "calico.yaml": serviceaccounts "calico-kube-controllers" is forbidden: User "system:node:master" cannot get resource "serviceaccounts" in API group "" in the namespace "kube-system": can only create tokens for individual service accounts Error from server (Forbidden): error when retrieving current configuration of: Resource: "/v1, Resource=serviceaccounts", GroupVersionKind: "/v1, Kind=ServiceAccount" Name: "calico-node", Namespace: "kube-system" from server for: "calico.yaml": serviceaccounts "calico-node" is forbidden: User "system:node:master" cannot get resource "serviceaccounts" in API group "" in the namespace "kube-system": can only create tokens for individual service accounts Error from server (Forbidden): error when retrieving current configuration of: Resource: "/v1, Resource=configmaps", GroupVersionKind: "/v1, Kind=ConfigMap" Name: "calico-config", Namespace: "kube-system" from server for: "calico.yaml": configmaps "calico-config" is forbidden: User "system:node:master" cannot get resource "configmaps" in API group "" in the namespace "kube-system": no relationship found between node 'master' and this object Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "bgpconfigurations.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "bgpconfigurations.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "bgppeers.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "bgppeers.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "blockaffinities.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "blockaffinities.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "caliconodestatuses.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "caliconodestatuses.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "clusterinformations.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "clusterinformations.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "felixconfigurations.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "felixconfigurations.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "globalnetworkpolicies.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "globalnetworkpolicies.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "globalnetworksets.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "globalnetworksets.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "hostendpoints.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "hostendpoints.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "ipamblocks.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "ipamblocks.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "ipamconfigs.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "ipamconfigs.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "ipamhandles.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "ipamhandles.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "ippools.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "ippools.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "ipreservations.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "ipreservations.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "kubecontrollersconfigurations.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "kubecontrollersconfigurations.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "networkpolicies.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "networkpolicies.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "apiextensions.k8s.io/v1, Resource=customresourcedefinitions", GroupVersionKind: "apiextensions.k8s.io/v1, Kind=CustomResourceDefinition" Name: "networksets.crd.projectcalico.org", Namespace: "" from server for: "calico.yaml": customresourcedefinitions.apiextensions.k8s.io "networksets.crd.projectcalico.org" is forbidden: User "system:node:master" cannot get resource "customresourcedefinitions" in API group "apiextensions.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "rbac.authorization.k8s.io/v1, Resource=clusterroles", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRole" Name: "calico-kube-controllers", Namespace: "" from server for: "calico.yaml": clusterroles.rbac.authorization.k8s.io "calico-kube-controllers" is forbidden: User "system:node:master" cannot get resource "clusterroles" in API group "rbac.authorization.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "rbac.authorization.k8s.io/v1, Resource=clusterroles", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRole" Name: "calico-node", Namespace: "" from server for: "calico.yaml": clusterroles.rbac.authorization.k8s.io "calico-node" is forbidden: User "system:node:master" cannot get resource "clusterroles" in API group "rbac.authorization.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "rbac.authorization.k8s.io/v1, Resource=clusterrolebindings", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRoleBinding" Name: "calico-kube-controllers", Namespace: "" from server for: "calico.yaml": clusterrolebindings.rbac.authorization.k8s.io "calico-kube-controllers" is forbidden: User "system:node:master" cannot get resource "clusterrolebindings" in API group "rbac.authorization.k8s.io" at the cluster scope Error from server (Forbidden): error when retrieving current configuration of: Resource: "rbac.authorization.k8s.io/v1, Resource=clusterrolebindings", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRoleBinding" Name: "calico-node", Namespace: "" from server for: "calico.yaml": clusterrolebindings.rbac.authorization.k8s.io "calico-node" is forbidden: User "system:node:master" cannot get resource "clusterrolebindings" in API group "rbac.authorization.k8s.io" at the cluster scope
05-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值