我有一个运行2个小兵的kubernetes集群.目前,我通过两个步骤访问我的服务:
kubectl get minions
)并将其设置为服务的publicIP.向公众公开服务的建议做法是什么?我的方法似乎是错误的,因为我对单个minion IP-s的IP进行了硬编码.它似乎也绕过了kubernetes服务的负载平衡功能,因为客户端必须直接访问在各个minions上运行的服务.
要设置复制控制器和pod,我使用:
id: frontend-controller
kind: ReplicationController
apiVersion: v1beta1
desiredState:
replicas: 2
replicaSelector:
name: frontend-pod
podTemplate:
desiredState:
manifest:
version: v1beta1
id: frontend-pod
containers:
- name: sinatra-docker-demo
image: madisn/sinatra_docker_demo
ports:
- name: http-server
containerPort: 4567
labels:
name: frontend-pod
Run Code Online (Sandbox Code Playgroud)
要设置服务(在获得minion ip-s之后):
kind: Service
id: frontend-service
apiVersion: v1beta1
port: 8000
containerPort: http-server
selector:
name: frontend-pod
labels:
name: frontend
publicIPs: [10.245.1.3, 10.245.1.4]
Run Code Online (Sandbox Code Playgroud) 我正在尝试为GKE上的负载均衡器设置静态外部IP,但没有运气.这是我的Kubernetes服务配置文件:
kind: Service
apiVersion: v1
metadata:
name: myAppService
spec:
selector:
app: myApp
ports:
- protocol: TCP
port: 3001
targetPort: 3001
type: LoadBalancer
loadBalancerIP: *********
Run Code Online (Sandbox Code Playgroud)
这不起作用.我希望看到我的外部IP为*********,但它只是说待处理:
? git:(master) kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ********* <none> 443/TCP 5m
myAppService ********* <pending> 3001:30126/TCP 5m
Run Code Online (Sandbox Code Playgroud)
更多细节:
? git:(master) kubectl describe services
Name: kubernetes
Namespace: default
Labels: component=apiserver
provider=kubernetes
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP: *********
Port: https 443/TCP
Endpoints: *********
Session Affinity: ClientIP
Events: <none>
Name: myAppService
Namespace: default …
Run Code Online (Sandbox Code Playgroud) 我目前有一个可用的前端和后端节点端口,其中包含使用 GKE 的 Google 管理证书的 Ingress 服务设置。
但是,我的问题是,默认情况下,当用户访问 samplesite.com 时,它默认使用 http。这意味着用户需要专门在浏览器中输入https://samplesite.com才能获得我网站的 https 版本。
如何正确禁用 GKE 入口上的 http,或者如何将所有流量重定向到 https?我知道这也可以在我的后端代码中强制完成,但我想分离关注点并在我的 Kubernetes 设置中处理这个问题。
这是我的 ingress.yaml 文件:
kind: Service
apiVersion: v1
metadata:
name: frontend-node-service
namespace: default
spec:
type: NodePort
selector:
app: frontend
ports:
- port: 5000
targetPort: 80
protocol: TCP
name: http
---
kind: Service
apiVersion: v1
metadata:
name: backend-node-service
namespace: default
spec:
type: NodePort
selector:
app: backend
ports:
- port: 8081
targetPort: 9229
protocol: TCP
name: http
--- …
Run Code Online (Sandbox Code Playgroud) docker google-cloud-platform kubernetes google-kubernetes-engine kubernetes-ingress