How to Exposing app in kubernetes with consul

12/17/2018

We have installed consul through helm charts on k8 cluster. Here, I have deployed one consul server and the rest are consul agents.

kubectl get pods
NAME                                                          READY     STATUS      RESTARTS   AGE
consul-7csp9                                                  1/1       Running     0          4h
consul-connect-injector-webhook-deployment-66d46867f6-wqtt7   1/1       Running     0          4h
consul-server-0                                               1/1       Running     0          4h
consul-sync-catalog-85f5654b89-9qblx                          1/1       Running     0          4h
consul-x4mqq                                                  1/1       Running     0          4h

We see that the nodes are registered onto the Consul Server. http://XX.XX.XX.XX/ui/kube/nodes

We have deployed an hello world application onto k8 cluster. This will bring-up Hello-World

kubectl get pods
NAME                                                          READY     STATUS      RESTARTS   AGE
consul-7csp9                                                  1/1       Running     0          4h
consul-connect-injector-webhook-deployment-66d46867f6-wqtt7   1/1       Running     0          4h
consul-server-0                                               1/1       Running     0          4h
consul-sync-catalog-85f5654b89-9qblx                          1/1       Running     0          4h
consul-x4mqq                                                  1/1       Running     0          4h
sampleapp-69bf9f84-ms55k                                      2/2       Running     0          4h

Below is the yaml file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sampleapp
spec:
  replicas: 1
selector:
matchLabels:
  app: sampleapp
template:
  metadata:
    labels:
      app: sampleapp
    annotations:
      "consul.hashicorp.com/connect-inject": "true"
  spec:
    containers:
    - name: sampleapp
      image: "docker-dev-repo.aws.com/sampleapp-java/helloworld-service:a8c9f65-65"
      ports:
      - containerPort: 8080
        name: http

Successful deployment of sampleapp, I see that sampleapp-proxy is registered in consul. and sampleapp-proxy is listed in kubernetes services. (This is because the toConsul and toK8S are passed as true during installation)

kubectl get services
NAME                          TYPE           CLUSTER-IP     EXTERNAL-IP                      PORT(S)                                                                   AGE
consul                        ExternalName   <none>         consul.service.test              <none>                                                                    4h
consul-connect-injector-svc   ClusterIP      XX.XX.XX.XX    <none>                           443/TCP                                                                   4h
consul-dns                    ClusterIP      XX.XX.XX.XX    <none>                           53/TCP,53/UDP                                                             4h
consul-server                 ClusterIP      None           <none>                           8500/TCP,8301/TCP,8301/UDP,8302/TCP,8302/UDP,8300/TCP,8600/TCP,8600/UDP   4h
consul-ui                     LoadBalancer   XX.XX.XX.XX    XX.XX.XX.XX                      80:32648/TCP                                                              4h
dns-test-proxy                ExternalName   <none>         dns-test-proxy.service.test      <none>                                                                    2h
fluentd-gcp-proxy             ExternalName   <none>         fluentd-gcp-proxy.service.test   <none>                                                                    33m
kubernetes                    ClusterIP      XX.XX.XX.XX    <none>                           443/TCP                                                                   5d
sampleapp-proxy               ExternalName   <none>         sampleapp-proxy.service.test     <none>                                                                    4h

How can I access my sampleapp? Should I expose my application as kube service again?

Earlier, without consul, we used a create a service for the sampleapp and expose the service as ingress. Using the Ingress Loadbalancer, we used to access our application.

-- Sunil Gajula
consul
kubernetes

1 Answer

12/25/2018

Consul does not provide any new ways to expose your apps. You need to create ingress Loadbalancer as before.

-- dds
Source: StackOverflow