Kubernetes Pods 状态始终未决
Kubernetes Pods status is always pending
请帮助我。我正在遵循本指南:https://pleasereleaseme.net/deploy-a-dockerized-asp-net-core-application-to-kubernetes-on-azure-using-a-vsts-ci-cd-pipeline-part-1/。我的 docker 图像已成功构建并推送到我的私有容器注册表,我的 CD 管道也正常。但是当我尝试使用 kubectl get pods 检查它时,状态总是待处理,当我尝试使用 kubectl describe pod k8s-aspnetcore-deployment-64648bb5ff-fxg2k
时,消息是:
Name: k8s-aspnetcore-deployment-64648bb5ff-fxg2k
Namespace: default
Node: <none>
Labels: app=k8s-aspnetcore
pod-template-hash=2020466199
Annotations: <none>
Status: Pending
IP:
Controlled By: ReplicaSet/k8s-aspnetcore-deployment-64648bb5ff
Containers:
k8s-aspnetcore:
Image: mycontainerregistryb007.azurecr.io/k8saspnetcore:2033
Port: 80/TCP
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-tr892 (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
default-token-tr892:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-tr892
Optional: false
QoS Class: BestEffort
Node-Selectors: beta.kubernetes.io/os=windows
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 3m (x57 over 19m) default-scheduler 0/1 nodes are available: 1 MatchNodeSelector.
这里是 kubectl describe deployment:
Name: k8s-aspnetcore-deployment
Namespace: default
CreationTimestamp: Sat, 21 Jul 2018 13:41:52 +0000
Labels: app=k8s-aspnetcore
Annotations: deployment.kubernetes.io/revision=2
Selector: app=k8s-aspnetcore
Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 5
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=k8s-aspnetcore
Containers:
k8s-aspnetcore:
Image: mycontainerregistryb007.azurecr.io/k8saspnetcore:2033
Port: 80/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: k8s-aspnetcore-deployment-64648bb5ff (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 26m deployment-controller Scaled up replica set k8s-aspnetcore-deployment-7f756cc78c to 1
Normal ScalingReplicaSet 26m deployment-controller Scaled up replica set k8s-aspnetcore-deployment-64648bb5ff to 1
Normal ScalingReplicaSet 26m deployment-controller Scaled down replica set k8s-aspnetcore-deployment-7f756cc78c to 0
这里是 kubectl 描述服务:
Name: k8s-aspnetcore-service
Namespace: default
Labels: version=test
Annotations: <none>
Selector: app=k8s-aspnetcore
Type: LoadBalancer
IP: 10.0.26.188
LoadBalancer Ingress: 40.112.73.28
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30282/TCP
Endpoints: <none>
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 26m service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 25m service-controller Ensured load balancer
我不知道我的 Kubernetes 集群设置是否有误,但这是我使用的脚本:
#!/bin/bash
azureSubscriptionId="xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxx"
resourceGroup="k8sResourceGroup"
clusterName="k8sCluster"
location="northeurope"
# Useful if you have more than one Aure subscription
az account set --subscription $azureSubscriptionId
# Resource group for cluster - only availble in certain regions at time of writing
az group create --location $location --name $resourceGroup
# Create actual cluster
az aks create --resource-group $resourceGroup --name $clusterName --node-count 1 --generate-ssh-keys
# Creates a config file at ~/.kube on local machine to tell kubectl which cluster it should work with
az aks get-credentials --resource-group $resourceGroup --name $clusterName
这是我的 deployment.yaml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: k8s-aspnetcore-deployment
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: k8s-aspnetcore
spec:
containers:
- name: k8s-aspnetcore
image: mycontainerregistryb007.azurecr.io/k8saspnetcore
ports:
- containerPort: 80
imagePullSecrets:
- name: k8ssecret
nodeSelector:
"beta.kubernetes.io/os": windows
这是我的 service.yaml:
kind: Service
metadata:
name: k8s-aspnetcore-service
labels:
version: test
spec:
selector:
app: k8s-aspnetcore
ports:
- port: 80
type: LoadBalancer
describe pod
输出底部的消息中描述了它们处于 Pending 状态的原因:MatchNodeSelector
。这意味着 Kubernetes 在您的集群中找不到能够满足 PodSpec 中指定的节点选择标准的节点。
具体来说,很可能是这些行:
nodeSelector:
"beta.kubernetes.io/os": windows
只有 kubectl describe nodes
会判断是否有可能满足该条件的节点
以@Matthew L Daniel 提到的内容为基础,标签键 "beta.kubernetes.io/os"
是任何 Kubernetes Node
中预先填充的默认标签之一,它表示底层 OS。
通过为 Pod
规范的 nodeSelector
属性 提供 label
定义,您是在告诉调度程序您希望 Pods
被管理通过 Deployment
对象仅落在符合此条件的 Node
上,这意味着它们必须放置在节点 运行 Windows OS 中。
- 但是如果没有节点符合这样的条件怎么办?
以下描述命令是 运行 在 Minikube 创建的集群设置上。
集群为单节点配置,节点名称为minikube
kubectl describe nodes minikube
描述输出的相关部分如下:
Name: minikube
Roles: master
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=minikube
node-role.kubernetes.io/master=
Annotations: node.alpha.kubernetes.io/ttl=0
volumes.kubernetes.io/controller-managed-attach-detach=true
CreationTimestamp: Wed, 11 Jul 2018 00:32:43 +0100
Taints: <none>
Unschedulable: false
正如您在 Labels
部分看到的,存在标签键 "beta.kubernetes.io/os"
的定义,但不是设置为值 "windows" 而是设置为 "linux" 代替。
请帮助我。我正在遵循本指南:https://pleasereleaseme.net/deploy-a-dockerized-asp-net-core-application-to-kubernetes-on-azure-using-a-vsts-ci-cd-pipeline-part-1/。我的 docker 图像已成功构建并推送到我的私有容器注册表,我的 CD 管道也正常。但是当我尝试使用 kubectl get pods 检查它时,状态总是待处理,当我尝试使用 kubectl describe pod k8s-aspnetcore-deployment-64648bb5ff-fxg2k
时,消息是:
Name: k8s-aspnetcore-deployment-64648bb5ff-fxg2k
Namespace: default
Node: <none>
Labels: app=k8s-aspnetcore
pod-template-hash=2020466199
Annotations: <none>
Status: Pending
IP:
Controlled By: ReplicaSet/k8s-aspnetcore-deployment-64648bb5ff
Containers:
k8s-aspnetcore:
Image: mycontainerregistryb007.azurecr.io/k8saspnetcore:2033
Port: 80/TCP
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-tr892 (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
default-token-tr892:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-tr892
Optional: false
QoS Class: BestEffort
Node-Selectors: beta.kubernetes.io/os=windows
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 3m (x57 over 19m) default-scheduler 0/1 nodes are available: 1 MatchNodeSelector.
这里是 kubectl describe deployment:
Name: k8s-aspnetcore-deployment
Namespace: default
CreationTimestamp: Sat, 21 Jul 2018 13:41:52 +0000
Labels: app=k8s-aspnetcore
Annotations: deployment.kubernetes.io/revision=2
Selector: app=k8s-aspnetcore
Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 5
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=k8s-aspnetcore
Containers:
k8s-aspnetcore:
Image: mycontainerregistryb007.azurecr.io/k8saspnetcore:2033
Port: 80/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: k8s-aspnetcore-deployment-64648bb5ff (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 26m deployment-controller Scaled up replica set k8s-aspnetcore-deployment-7f756cc78c to 1
Normal ScalingReplicaSet 26m deployment-controller Scaled up replica set k8s-aspnetcore-deployment-64648bb5ff to 1
Normal ScalingReplicaSet 26m deployment-controller Scaled down replica set k8s-aspnetcore-deployment-7f756cc78c to 0
这里是 kubectl 描述服务:
Name: k8s-aspnetcore-service
Namespace: default
Labels: version=test
Annotations: <none>
Selector: app=k8s-aspnetcore
Type: LoadBalancer
IP: 10.0.26.188
LoadBalancer Ingress: 40.112.73.28
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30282/TCP
Endpoints: <none>
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 26m service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 25m service-controller Ensured load balancer
我不知道我的 Kubernetes 集群设置是否有误,但这是我使用的脚本:
#!/bin/bash
azureSubscriptionId="xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxx"
resourceGroup="k8sResourceGroup"
clusterName="k8sCluster"
location="northeurope"
# Useful if you have more than one Aure subscription
az account set --subscription $azureSubscriptionId
# Resource group for cluster - only availble in certain regions at time of writing
az group create --location $location --name $resourceGroup
# Create actual cluster
az aks create --resource-group $resourceGroup --name $clusterName --node-count 1 --generate-ssh-keys
# Creates a config file at ~/.kube on local machine to tell kubectl which cluster it should work with
az aks get-credentials --resource-group $resourceGroup --name $clusterName
这是我的 deployment.yaml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: k8s-aspnetcore-deployment
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: k8s-aspnetcore
spec:
containers:
- name: k8s-aspnetcore
image: mycontainerregistryb007.azurecr.io/k8saspnetcore
ports:
- containerPort: 80
imagePullSecrets:
- name: k8ssecret
nodeSelector:
"beta.kubernetes.io/os": windows
这是我的 service.yaml:
kind: Service
metadata:
name: k8s-aspnetcore-service
labels:
version: test
spec:
selector:
app: k8s-aspnetcore
ports:
- port: 80
type: LoadBalancer
describe pod
输出底部的消息中描述了它们处于 Pending 状态的原因:MatchNodeSelector
。这意味着 Kubernetes 在您的集群中找不到能够满足 PodSpec 中指定的节点选择标准的节点。
具体来说,很可能是这些行:
nodeSelector:
"beta.kubernetes.io/os": windows
只有 kubectl describe nodes
会判断是否有可能满足该条件的节点
以@Matthew L Daniel 提到的内容为基础,标签键 "beta.kubernetes.io/os"
是任何 Kubernetes Node
中预先填充的默认标签之一,它表示底层 OS。
通过为 Pod
规范的 nodeSelector
属性 提供 label
定义,您是在告诉调度程序您希望 Pods
被管理通过 Deployment
对象仅落在符合此条件的 Node
上,这意味着它们必须放置在节点 运行 Windows OS 中。
- 但是如果没有节点符合这样的条件怎么办?
以下描述命令是 运行 在 Minikube 创建的集群设置上。 集群为单节点配置,节点名称为minikube
kubectl describe nodes minikube
描述输出的相关部分如下:
Name: minikube
Roles: master
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=minikube
node-role.kubernetes.io/master=
Annotations: node.alpha.kubernetes.io/ttl=0
volumes.kubernetes.io/controller-managed-attach-detach=true
CreationTimestamp: Wed, 11 Jul 2018 00:32:43 +0100
Taints: <none>
Unschedulable: false
正如您在 Labels
部分看到的,存在标签键 "beta.kubernetes.io/os"
的定义,但不是设置为值 "windows" 而是设置为 "linux" 代替。