0

我已经部署了一个 Drupal 实例,但我看到实例端点不可见,尽管容器部署成功。

容器日志不指向任何方向

apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drupal
      type: frontend
  template:
    metadata:
      labels:
        app: drupal
    spec:
      containers:
      - name: drupal
        image: drupal
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
 
**********************
apiVersion: v1
kind: Service
metadata:
  name: drupal-service
 
spec: 
  type: NodePort
  ports: 
    - targetPort: 80
      port: 80
      nodePort: 30010
  selector: 
      app: drupal
      type: frontend
************************`
root@ip-172-31-32-54:~# microk8s.kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
drupal-deployment-6fdd7975f-l4j2z   1/1     Running   0          9h
drupal-deployment-6fdd7975f-p7sfz   1/1     Running   0          9h
root@ip-172-31-32-54:~# microk8s.kubectl get services
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
drupal-service   NodePort    10.152.183.6   <none>        80:30010/TCP   9h
kubernetes       ClusterIP   10.152.183.1   <none>        443/TCP        34h
***********************
root@ip-172-31-32-54:~# microk8s.kubectl describe service drupal-service
Name:                     drupal-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=drupal,type=frontend
Type:                     NodePort
IP:                       10.152.183.6
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30010/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

任何方向都非常有帮助。

注意:这在使用命令运行容器时非常有效

docker run --name some-drupal -p 8080:80 -d drupal

谢谢你,阿尼什

4

1 回答 1

1

您的服务选择器有两个值:

Selector:                 app=drupal,type=frontend

但是您的 pod 只有其中之一:

spec:
  template:
    metadata:
      labels:
        app: drupal

只需确保服务所需的所有标签都实际存在于 pod 上。

如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drupal
      type: frontend
  template:
    metadata:
      labels:
        app: drupal
        type: frontend   #     <--------- look here
    spec:
      containers:
      - name: drupal
        image: drupal
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
于 2020-07-13T11:01:42.907 回答