anchor.diff:  [source, text]
   ----
   CONTAINER ID        IMAGE                                                                               COMMAND                CREATED             STATUS              PORTS               NAMES
  -2b92c80630d5        gcr.io/google_containers/etcd:2.0.9                                                 "/usr/local/bin/etcd   5 hours ago         Up 5 hours                              k8s_etcd-container.ec4297e5_etcd-server-kubernetes-master_default_3595ac402f3a17c29dab95f3e0f64c76_56fa3dce                        
  -64c375f8030b        gcr.io/google_containers/kube-apiserver:465b93ab80b30057f9c2ef12f30450c3            "/bin/sh -c '/usr/lo   5 hours ago         Up 5 hours                              k8s_kube-apiserver.f4e485e1_kube-apiserver-kubernetes-master_default_c6b19d563bdbcfb0af80b57377ee905c_2f16c239                     
  -d7d9d40bd479        gcr.io/google_containers/kube-controller-manager:572696d43ca87cd1fe0c774bac3a5f4b   "/bin/sh -c '/usr/lo   5 hours ago         Up 5 hours                              k8s_kube-controller-manager.70259e73_kube-controller-manager-kubernetes-master_default_8f8db766ebc90a00a99244c362284cf1_6eff7640   
  -13251c4df211        gcr.io/google_containers/kube-scheduler:d1f640dfb379f64daf3ae44286014821            "/bin/sh -c '/usr/lo   5 hours ago         Up 5 hours                              k8s_kube-scheduler.f53b6329_kube-scheduler-kubernetes-master_default_1f3b1657f7f1af67ce9f929d78c64695_de632a80                     
  -b1809bdabd9c        gcr.io/google_containers/pause:0.8.0                                                "/pause"               5 hours ago         Up 5 hours                              k8s_POD.e4cc795_kube-apiserver-kubernetes-master_default_c6b19d563bdbcfb0af80b57377ee905c_767dadb1                                 
  -280baf845b00        gcr.io/google_containers/pause:0.8.0                                                "/pause"               5 hours ago         Up 5 hours                              k8s_POD.e4cc795_kube-scheduler-kubernetes-master_default_1f3b1657f7f1af67ce9f929d78c64695_52a4ca74                                 
  -615a314a35bf        gcr.io/google_containers/pause:0.8.0                                                "/pause"               5 hours ago         Up 5 hours                              k8s_POD.e4cc795_kube-controller-manager-kubernetes-master_default_8f8db766ebc90a00a99244c362284cf1_97cc1739                        
  -7a554eea05f3        gcr.io/google_containers/pause:0.8.0                                                "/pause"               5 hours ago         Up 5 hours                              k8s_POD.e4cc795_etcd-server-kubernetes-master_default_3595ac402f3a17c29dab95f3e0f64c76_593b9807 
  -----
  -
  -
  -
  +dc59a764953c        gcr.io/google_containers/etcd:2.0.12                                                "/bin/sh -c '/usr/lo   20 hours ago        Up 20 hours                             k8s_etcd-container.fa2ab1d9_etcd-server-kubernetes-master_default_7b64ecafde589b94a342982699601a19_2b69c4d5                        
  +b722e22d3ddb        gcr.io/google_containers/kube-scheduler:d1107ff3b8fcdcbf5a9d78d9d6dbafb1            "/bin/sh -c '/usr/lo   20 hours ago        Up 20 hours                             k8s_kube-scheduler.7501c229_kube-scheduler-kubernetes-master_default_98b354f725c1589ea5a12119795546ae_b81b9740                     
  +38a73e342866        gcr.io/google_containers/kube-controller-manager:fafaf8100ccc963e643b55e35386d713   "/bin/sh -c '/usr/lo   20 hours ago        Up 20 hours                             k8s_kube-controller-manager.db050993_kube-controller-manager-kubernetes-master_default_f5c25224fbfb2de87e1e5c35e6b3a293_dcd4cb5d   
  +01001de6409e        gcr.io/google_containers/kube-apiserver:cff9e185796caa8b281e7d961aea828b            "/bin/sh -c '/usr/lo   20 hours ago        Up 20 hours                             k8s_kube-apiserver.7e06f4e1_kube-apiserver-kubernetes-master_default_829f8c23fd5fc7951253cac7618447fc_b39c0a5d                     
  +0f8ccb144ece        gcr.io/google_containers/pause:0.8.0                                                "/pause"               20 hours ago        Up 20 hours                             k8s_POD.e4cc795_kube-scheduler-kubernetes-master_default_98b354f725c1589ea5a12119795546ae_eb1efcac                                 
  +0b8f527456c0        gcr.io/google_containers/pause:0.8.0                                                "/pause"               20 hours ago        Up 20 hours                             k8s_POD.e4cc795_kube-apiserver-kubernetes-master_default_829f8c23fd5fc7951253cac7618447fc_5dd4dee7                                 
  +39d9c41ab1a2        gcr.io/google_containers/pause:0.8.0                                                "/pause"               20 hours ago        Up 20 hours                             k8s_POD.e4cc795_kube-controller-manager-kubernetes-master_default_f5c25224fbfb2de87e1e5c35e6b3a293_522972ae                        
  +d970ddff7046        gcr.io/google_containers/pause:0.8.0                                                "/pause"               20 hours ago        Up 20 hours                             k8s_POD.e4cc795_etcd-server-kubernetes-master_default_7b64ecafde589b94a342982699601a19_fa75b27f 
  +----
  
positive.code: 
  Kubernetes services is an abstraction which defines a logical set of pods. A service is typically back-ended by one or more physical pods (associated using labels), and it has a permanent IP address that can be used by other pods/applications. For example, WildFly pod can not directly connect to a MySQL pod but can connect to MySQL service. In essence, Kubernetes service offers clients an IP and port pair which, when accessed, redirects to the appropriate backends.
  
  .Kubernetes Services
  image::../images/kubernetes-services.png[]
  
  NOTE: In this case, all the pods are running on a single minion. This is because, that is the default number for a Kubernetes cluster. The pod can very be on another minion if more minions exist in the cluster.
  
  Any Service that a Pod wants to access must be created before the Pod itself, or else the environment variables will not be populated.
  
  #### Start MySQL Service
  
  . Start MySQL service as:
  +
  [source, text]
  ----
  ./cluster/kubectl.sh create -f ../../attendees/kubernetes/mysql-service.yaml
  ----
  +
  It uses the following configuration file:
  +
  [source, yaml]
  ----
  id: mysql
  kind: Service
  apiVersion: v1beta3
  metadata:
    name: mysql
    labels:
      name: mysql
      context: docker-k8s-lab
  spec:
    ports:
      - port: 3306
    selector:
      name: mysql
    labels:
      name: mysql
  ----
  +
  . Check that the service is created:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh get se -l context=docker-k8s-lab
  NAME      LABELS                              SELECTOR     IP(S)            PORT(S)
  mysql     context=docker-k8s-lab,name=mysql   name=mysql   10.247.141.208   3306/TCP
  ----
  +
  Note that the label used during the creation is used to query the service.
  +
  When a Pod is run on a node, the kubelet adds a set of environment variables for each active Service. 
  +
  It supports both Docker links compatible variables and simpler `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables, where the Service name is upper-cased and dashes are converted to underscores.
  +
  Our service name is ``mysql'' and so `MYSQL_SERVICE_HOST` and `MYSQL_SERVICE_PORT` variables are available to other pods.
  
  Send a Pull Request for https://github.com/javaee-samples/docker-java/issues/62[#62].
  
  #### Start MySQL Replication Controller
  
  . Start MySQL replication controller as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh --v=5 create -f ../../attendees/kubernetes/mysql.yaml
  I0616 19:41:55.441461    8346 defaults.go:174] creating security context for container mysql
  replicationcontrollers/mysql
  ----
  +
  It uses the following configuration file:
  +
  [source, yaml]
  ----
  kind: ReplicationController
  apiVersion: v1beta3
  metadata:
    name: mysql
    labels:
      name: mysql
      context: docker-k8s-lab
  spec:
    replicas: 1
    selector:
      name: mysql
    template:
      metadata:
        labels:
          name: mysql
          context: docker-k8s-lab
      spec:
        containers:
          - name: mysql
            image: mysql:latest
            env:
              - name: MYSQL_USER
                value: mysql
              - name: MYSQL_PASSWORD
                value: mysql
              - name: MYSQL_DATABASE
                value: sample
              - name: MYSQL_ROOT_PASSWORD
                value: supersecret
            ports:
              - containerPort: 3306
                hostPort: 3306
  ----
  +
  Once again, the ``docker-k8s-lab'' label is used. This simplifies querying the created pods later on.
  +
  . Verify MySQL replication controller as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh get rc -l context=docker-k8s-lab
  CONTROLLER   CONTAINER(S)   IMAGE(S)       SELECTOR     REPLICAS
  mysql        mysql          mysql:latest   name=mysql   1
  ----
  +
  . Check the status of MySQL pod as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh get po -l context=docker-k8s-lab
  POD           IP        CONTAINER(S)   IMAGE(S)       HOST          LABELS                              STATUS    CREATED          MESSAGE
  mysql-7lq67                                           10.245.1.3/   context=docker-k8s-lab,name=mysql   Pending   About a minute   
                          mysql          mysql:latest                  
  ----
  
  #### Start WildFly Replication Controller
  
  . Start WildFly replication controller as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh --v=5 create -f ../../attendees/kubernetes/wildfly.yaml
  I0616 18:59:00.563099    7849 defaults.go:174] creating security context for container wildfly
  replicationcontrollers/wildfly
  ----
  +
  It uses the following configuration file:
  +
  [source, yaml]
  ----
  kind: ReplicationController
  apiVersion: v1beta3
  metadata:
    name: wildfly
    labels:
      name: wildfly
      context: docker-k8s-lab
  spec:
    replicas: 1
    selector:
      name: wildfly-server
    template:
      metadata:
        labels:
          name: wildfly-server
          context: docker-k8s-lab
      spec:
        containers:
          - name: wildfly
            image: arungupta/wildfly-mysql-javaee7:k8s
            ports:
              - containerPort: 8080
                hostPort: 8080
  ----
  +
  . Verify WildFly replication controller using ``docker-k8s-lab'' label as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh get rc -l context=docker-k8s-lab
  CONTROLLER   CONTAINER(S)   IMAGE(S)                              SELECTOR              REPLICAS
  mysql        mysql          mysql:latest                          name=mysql            1
  wildfly      wildfly        arungupta/wildfly-mysql-javaee7:k8s   name=wildfly-server   1
  ----
  +
  . Check the status of WildFly pod as:
  +
  [source, text]
  ----
  > ./cluster/kubectl.sh get pod -l context=docker-k8s-lab
  POD             IP        CONTAINER(S)   IMAGE(S)                              HOST          LABELS                                       STATUS    CREATED      MESSAGE
  mysql-7lq67                                                                    10.245.1.3/   context=docker-k8s-lab,name=mysql            Pending   3 minutes    
                            mysql          mysql:latest                                                                                                            
  wildfly-o0nw6                                                                  10.245.1.3/   context=docker-k8s-lab,name=wildfly-server   Pending   45 seconds   
                            wildfly        arungupta/wildfly-mysql-javaee7:k8s
  ----
  
  Make sure the status of both WildFly and MySQL pod is changed to ``running''. It will look like:
  
  [source, text]
  ----
  > ./cluster/kubectl.sh get pod -l context=docker-k8s-lab
  POD             IP            CONTAINER(S)   IMAGE(S)                              HOST                    LABELS                                       STATUS    CREATED      MESSAGE
  mysql-7lq67     172.17.0.9                                                         10.245.1.3/10.245.1.3   context=docker-k8s-lab,name=mysql            Running   14 minutes   
                                mysql          mysql:latest                                                                                               Running   10 minutes   
  wildfly-o0nw6   172.17.0.10                                                        10.245.1.3/10.245.1.3   context=docker-k8s-lab,name=wildfly-server   Running   11 minutes   
                                wildfly        arungupta/wildfly-mysql-javaee7:k8s                                                                        Running   26 seconds   
  ----
  
  NOTE: Takes a while for all the pods to start. It took ~25 minutes on a 16 GB, i7 Mac OS X.
  
  ### Access Java EE Application
  
  http://<pod_ip>:8080/employees/resources/employees
  
  ### Self-healing Pods
  
  . Delete the WildFly pod
  . Wait for k8s to restart the pod because of RC
  
  ### Application Logs
  
  . Login to Minion-1 VM:
  +
  [source, text]
  ----
  
negative.code: ----
  [vagrant@kubernetes-master ~]$ su - 
  Password: 
  [root@kubernetes-master ~]#
  ----
  +
  Default root password for VM images created by Vagrant is ``vagrant''.
  