• Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

kube-keepalived-vip cloud provider for Kubernetes 1.6+

keepalived-cloud-provider Build Status

This project is in alpha state, and should be used with caution. Whilst it is quite simple, there are currently minimal unit tests and no integration tests. Contributions are very welcome.

keepalived-cloud-provider is an out-of-tree Kubernetes cloud provider implementation (more info). It will manage and automatically update a ConfigMap for kube-keepalived-vip, which will then automatically create load balanced IP addresses in the specified CIDR. This allows users in bare-metal environments to use services with type: LoadBalancer set.

This is perfect if you want to run Kubernetes in network in which you have a routable CIDR that you want to expose your services in.

Getting started

To use the cloud provider, we'll need to do a few things:

  • Install kube-keepalived-vip
  • Set --cloud-provider=external on our kube-controller-manager master component
  • Deploy keepalived-cloud-provider
  • Create a service with type: LoadBalancer!

Install kube-keepalived-vip

Full instructions are available in the kube-keepalived-vip repository.

Briefly, we simply need to create a DaemonSet:

$ kubectl create -f vip-daemonset.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: kube-keepalived-vip
  namespace: kube-system
spec:
  template:
    metadata:
      labels:
        name: kube-keepalived-vip
    spec:
      hostNetwork: true
      containers:
        - image: gcr.io/google_containers/kube-keepalived-vip:0.9
          name: kube-keepalived-vip
          imagePullPolicy: Always
          securityContext:
            privileged: true
          volumeMounts:
            - mountPath: /lib/modules
              name: modules
              readOnly: true
            - mountPath: /dev
              name: dev
          # use downward API
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          # to use unicast
          args:
          - --services-configmap=kube-system/vip-configmap
          # unicast uses the ip of the nodes instead of multicast
          # this is useful if running in cloud providers (like AWS)
          #- --use-unicast=true
      volumes:
        - name: modules
          hostPath:
            path: /lib/modules
        - name: dev
          hostPath:
            path: /dev
      nodeSelector:
        # type: worker # adjust this to match your worker nodes
---
## We also create an empty ConfigMap to hold our config
apiVersion: v1
kind: ConfigMap
metadata:
  name: vip-configmap
  namespace: kube-system
data:

Configure kube-controller-manager

In order to use the currently alpha external cloud provider functionality, we need to set a flag on the kube-controller-manager component. How to do this depends on how you deployed your cluster, but if deployed with kubeadm you should edit /etc/kubernetes/manifests/kube-controller-manager.yaml. and add --cloud-provider external to the command section.

If you are using the kubeadm config file, then the following fragment will enable the external cloud provider.

controllerManagerExtraArgs:
  cloud-provider: external

Deploy keepalived-cloud-provider

keepalived-cloud-provider can be deployed with a simple Kubernetes Deployment, and performs leader election like other kubernetes master components. It is therefore safe to run multiple replicas of the keepalived-cloud-provider pod.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  labels:
    app: keepalived-cloud-provider
  name: keepalived-cloud-provider
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: keepalived-cloud-provider
  strategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ""
        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
      labels:
        app: keepalived-cloud-provider
    spec:
      containers:
      - name: keepalived-cloud-provider
        image: quay.io/munnerz/keepalived-cloud-provider:0.0.1
        imagePullPolicy: IfNotPresent
        env:
        - name: KEEPALIVED_NAMESPACE
          value: kube-system
        - name: KEEPALIVED_CONFIG_MAP
          value: vip-configmap
        - name: KEEPALIVED_SERVICE_CIDR
          value: 10.210.38.100/26 #ย pick a CIDR that is explicitly reserved for keepalived
        volumeMounts:
        - name: certs
          mountPath: /etc/ssl/certs
        resources:
          requests:
            cpu: 200m
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10252
            host: 127.0.0.1
          initialDelaySeconds: 15
          timeoutSeconds: 15
          failureThreshold: 8
      volumes:
      - name: certs
        hostPath:
          path: /etc/ssl/certs

Create a service

Once keepalived-cloud-provider is up and running, you should be able to create service with type: LoadBalancer:

$ kubectl expose deployment example-com --name=example-com --type=LoadBalancer

keepalived-cloud-provider will also honour the loadBalancerIp field in a service.spec, and will configure a load balancer with the provided IP regardless whether it is within the KEEPALIVED_SERVICE_CIDR

$ kubectl get services
NAME              CLUSTER-IP       EXTERNAL-IP    PORT(S)        AGE
test              10.98.31.230     10.210.38.66   80:31877/TCP   3s
test2             10.107.177.153   10.210.38.65   80:31261/TCP   12m

Advanced: Configure forwarding method for the service

The kube-keepalived-vip service supports both the NAT and DR methods of IPVS forwarding for the service traffic. The default forwarding method is NAT. Depending on your network topology, you may need to change that to DR (direct routing). To change this globally, you can set the environment variable KEEPALIVED_DEFAULT_FORWARD_METHOD to NAT or DR. To change it on a per service basis, then specify the method via the k8s.co/keepalived-forward-method annotation on the service as shown below:

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    k8s-app: nginx
  annotations:
    k8s.co/keepalived-forward-method: DR
spec:
  type: LoadBalancer
  ports:
  - port: 443
    targetPort: 8080
    protocol: TCP
    name: http
  selector:
    k8s-app: nginx

More information on the differences between NAT and DR methods can be found in the Keepalived documentation

More Repositories

1

kube-plex

Scalable Plex Media Server on Kubernetes -- dispatch transcode jobs as pods on your cluster!
Go
1,223
star
2

kubewg

Use Kubernetes to manage & distribute Wireguard configuration
Go
176
star
3

k8s-api-pager-demo

A demo Kubernetes controller & API server
Go
39
star
4

scaleway-kubernetes

Scaleway image to run Kubernetes
Shell
19
star
5

kube-acme

Retrieve certificates for Kubernetes Ingress resources from acme servers and store as secrets
Go
13
star
6

crd-schema-fuzz

Fuzz testing for Kubernetes CustomResourceDefinition schemas
Go
11
star
7

k8s-gluster-petset

Kubernetes PetSet for running GlusterFS
Makefile
11
star
8

ddebug

Quickly debug locked-down docker containers
Shell
10
star
9

godep-to-dep

Tool for converting Godeps.json files into Gopkg.toml
Go
8
star
10

helmsploit

A simple demonstration of privilege escalation via the default Tiller gRPC API
6
star
11

goautoneg

Mirror of bitbucket.org/ww/goautoneg
Go
6
star
12

metaldata

Open-source metadata service for private cloud environments
Go
4
star
13

haproxy

HAProxy configuration generator
Go
3
star
14

quayio-bq-exporter

Export Quay.io usage logs to BigQuery
Go
3
star
15

Dripwn

Grabs Zephyr firmware binaries from iPhones.
3
star
16

apiextensions-ca-helper

A Kubernetes CronJob to automatically update APIService and Webhook resources with the contents of Secrets or files on disk
Go
2
star
17

rpi-builder-docker

Raspberry Pi image builder using Docker
Makefile
2
star
18

manifest-splitter

Split up Kubernetes manifests into directories suitable for Anthos Config Management
Go
2
star
19

hugo-multiversion

A CLI tool to make managing multi-version Hugo sites easier
Go
2
star
20

picctv

PiCCTV Dissertation Project
Python
1
star
21

etcd-operator-poc

Go
1
star
22

ssl-checker

Basic report on SSL certificates over HTTP
Go
1
star
23

charts

Helm charts repository
Smarty
1
star
24

k8s-co

k8s.co public blog
HTML
1
star
25

gen-apidocs-img

Docker image containing utilities used to generate reference API documentation for Kubernetes API based projects
Shell
1
star
26

RuneScape-Private-Server-Emulator

An emulator for the popular online game, RuneScape
Java
1
star
27

k8s-emptypv

A FlexVolume plugin & dynamic volume provisioner for empty persistent volumes
1
star
28

django-plexauth

Django plex.tv authentication backend
Python
1
star