Using a Service of LoadBalancer type on Cloud Provider OpenStack

This explains how to configure cluster-api-provider-openstack to use a Service of LoadBalancer type on Cloud Provider OpenStack.
OpenStack Octavia intallation is based on Installing OpenStack Octavia Stein release on Ubuntu 18.04 manually .

Configure

Cloud Provider OpenStack configuration is defined in the generate-yaml.sh file. You must add LoadBalancer section to the OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN environment variable value like the following. By adding this, the /etc/kubernetes/cloud.conf file in the master node will be updated.

# Basic cloud.conf, no LB configuration as that data is not known yet.
OPENSTACK_CLOUD_PROVIDER_CONF_PLAIN="[Global]
auth-url=$AUTH_URL
username=\"$USERNAME\"
password=\"$PASSWORD\"
region=\"$REGION\"
tenant-id=\"$PROJECT_ID\"
domain-name=\"$DOMAIN_NAME\"
[LoadBalancer]
lb-version=v2
use-octavia=true
floating-network-id=5f11f552-7254-47ac-bda3-e8c03b1443cd
create-monitor=true
monitor-delay=60s
monitor-timeout=30s
monitor-max-retries=5
"

After creating a Kubernetes cluster by cluster-api-provider-openstack, login to the master node and check /etc/kubernetes/cloud.conf file that LoadBalancer section was added.

ubuntu@openstack-master-xmd6r:~$ sudo cat /etc/kubernetes/cloud.conf
[Global]
auth-url=http://<controller>:5000/
username="demo"
password="<password>""
region="RegionOne"
tenant-id="<tenant-id>"
domain-name="Default"
[LoadBalancer]
lb-version=v2
use-octavia=true
floating-network-id=<floating-network-id>
create-monitor=true
monitor-delay=60s
monitor-timeout=30s
monitor-max-retries=5

Testing deployment

This is based on Exposing applications using services of LoadBalancer type

ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ kubectl --kubeconfig=kubeconfig run echoserver --image=gcr.io/google-containers/echoserver:1.10 --port=8080
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/echoserver created
ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ kubectl --kubeconfig=kubeconfig get deploy
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
echoserver   1/1     1            1           29s

ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ cat <<EOF > loadbalancer.yaml
> ---
> kind: Service
> apiVersion: v1
> metadata:
>   name: loadbalanced-service
> spec:
>   selector:
>     run: echoserver
>   type: LoadBalancer
>   ports:
>   - port: 80
>     targetPort: 8080
>     protocol: TCP
> EOF
ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ cat loadbalancer.yaml
---
kind: Service
apiVersion: v1
metadata:
  name: loadbalanced-service
spec:
  selector:
    run: echoserver
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ kubectl --kubeconfig=kubeconfig apply -f loadbalancer.yaml
service/loadbalanced-service created
ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ kubectl --kubeconfig=kubeconfig get service loadbalanced-service
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
loadbalanced-service   LoadBalancer   10.100.237.171   <pending>     80:31500/TCP   22s
ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ kubectl --kubeconfig=kubeconfig get service loadbalanced
-service -w
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
loadbalanced-service   LoadBalancer   10.100.237.171   <pending>     80:31500/TCP   29s
loadbalanced-service   LoadBalancer   10.100.237.171   10.0.0.228    80:31500/TCP   47s

ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$ curl 10.0.0.228


Hostname: echoserver-785b4d845-dgr9p

Pod Information:
        -no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=172.16.1.126
        method=GET
        real path=/
        query=
        request_version=1.1
        request_scheme=http
        request_uri=http://10.0.0.228:8080/

Request Headers:
        accept=*/*
        host=10.0.0.228
        user-agent=curl/7.58.0

Request Body:
        -no body in request-

ubuntu@k8s:~/go/src/sigs.k8s.io/cluster-api-provider-openstack/cmd/clusterctl$

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください