[英]can't expose kubernetes service aws ec2
我已經使用 AWS ec2 使用 jenkins 到 kubernetes 進行自動化部署,但我無法訪問它
outside`ubuntu@ip-172-31-32-236:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
node-app-55b7788b4b-b5rrb 1/1 Running 2 22h
ubuntu@ip-172-31-32-236:~$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
node-app 1/1 1 1 22h
ubuntu@ip-172-31-32-236:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d17h
lb-service LoadBalancer 10.109.120.200 <pending> 9005:31694/TCP 18h
我正在嘗試 ClusterIP、NodePort 和 LoadBalancer,但無法訪問互聯網。 沒有外部 IP。
Name: node-app-55b7788b4b-b5rrb
Namespace: default
Priority: 0
Node: worker01/172.31.2.82
Start Time: Mon, 19 Sep 2022 08:10:23 +0000
Labels: app=node-app
pod-template-hash=55b7788b4b
Annotations: <none>
Status: Running
IP: 10.244.1.46
IPs:
IP: 10.244.1.46
Controlled By: ReplicaSet/node-app-55b7788b4b
Containers:
node-app:
Container ID: docker://6b21adefe9d81f7ec96a7e50803aa999ea72aeaa09d5535b0757f19ac0a2a03a
Image: <harbor_url>/node/node-app:81
Image ID: docker-pullable://<harbor_url>/node/node-app@sha256:c1b7fbb01add4e6c89507b6413ce34d618d08629031fdc669fa05d0290d2e4b9
Port: 9005/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 20 Sep 2022 06:08:50 +0000
Last State: Terminated
Reason: Error
Exit Code: 137
Started: Mon, 19 Sep 2022 11:02:52 +0000
Finished: Mon, 19 Sep 2022 11:31:27 +0000
Ready: True
Restart Count: 2
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-rjgl9 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-rjgl9:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
這是服務
ubuntu@ip-172-31-32-236:~$ kubectl describe service lb-service
Name: lb-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=node-app
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.109.120.200
IPs: 10.109.120.200
Port: <unset> 9005/TCP
TargetPort: 80/TCP
NodePort: <unset> 31694/TCP
Endpoints: 10.244.1.46:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
.yaml 文件
apiVersion: apps/v1
kind: Deployment # Kubernetes resource kind we are creating
metadata:
name: node-app
spec:
selector:
matchLabels:
app: node-app
replicas: 1 # Number of replicas that will be created for this deployment
template:
metadata:
labels:
app: node-app
spec:
containers:
- name: node-app
image: <harbor_url>/node/node-app:$BUILD_NUMBER # Image that will be used to containers in the cluster
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9005 # The port that the container is running on in the cluster
imagePullSecrets:
- name: harbor-reg
---
apiVersion: v1 # Kubernetes API version
kind: Service # Kubernetes resource kind we are creating
metadata: # Metadata of the resource kind we are creating
name: node-svc
spec:
selector:
app: node-app
ports:
- protocol: "TCP"
port: 9005 # The port that the service is running on in the cluster
targetPort: 80 # The port exposed by the service
type: LoadBalancer # type of the service.
我將法蘭絨用於網絡策略
ubuntu@ip-172-31-32-236:~$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default node-app-55b7788b4b-b5rrb 1/1 Running 2 22h
kube-flannel kube-flannel-ds-j88kj 1/1 Running 6 7d18h
kube-flannel kube-flannel-ds-lb2cp 1/1 Running 10 7d18h
kube-system coredns-558bd4d5db-58kt2 1/1 Running 7 7d18h
kube-system coredns-558bd4d5db-mnsjl 1/1 Running 8 7d18h
kube-system etcd-ip-172-31-32-236 1/1 Running 9 7d18h
kube-system kube-apiserver-ip-172-31-32-236 1/1 Running 8 7d18h
kube-system kube-controller-manager-ip-172-31-32-236 1/1 Running 9 7d18h
kube-system kube-proxy-4vv72 1/1 Running 6 7d18h
kube-system kube-proxy-qxtsz 1/1 Running 9 7d18h
kube-system kube-scheduler-ip-172-31-32-236 1/1 Running 9 7d18h
我也在嘗試在工作節點和主節點上使用公共 IP 訪問它,但我發現死路一條。
不知道你是如何安裝Harbor的。
首先,您應該使用 DNS Harbor.local 在 AWS 中創建一個負載均衡器,然后您可以獲得它的外部 IP 地址。
其次,使用 loadBalancer 設置部署 Harbor。
git clone https://github.com/goharbor/harbor-helm
cd harbor-helm
helm install myrelease . --set expose.type=loadBalancer,expose.tls.auto.commonName=harbor.local,externalURL=https://harbor.local
部署完成后,您可以將harbor.local 添加到您的DNS 或更新客戶端機器的/etc/hosts。
<IP address> harbor.local
然后嘗試登錄以使用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.