Finding the URL for an AKS Cluster

2019-08-19 21:48发布

问题:

I've set-up an AKS cluster and am now trying to connect to it. My deployment YAML is here:

apiVersion: v1
kind: Pod
spec: 
  containers:
    - name: dockertest20190205080020
      image: dockertest20190205080020.azurecr.io/dockertest
      ports:
      - containerPort: 443
metadata: 
  name: my-test

If I run the dashboard, I get this:

Which looks like it should be telling me the external endpoint, but isn't. I have a theory that this is because the Yaml file is only deploying a Pod, which is in some way not able to expose an endpoint - is that the case and if so, why? Otherwise, how can I find this endpoint?

回答1:

Thats not how that works, you need to read up on basic kubernetes concept. Pods are only container, to expose pods you need to create services (and you need labels), to expose pods externally you need to set service type to LoadBalancer. You probably want to use deployments instead of pods, its a lot easier\reliable.

https://kubernetes.io/docs/concepts/services-networking/service/
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

so in short, you need to add labels to your pod and create a service of type load balancer with selectors that match your pods labels

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 443
  type: LoadBalancer