diff --git a/k8s/consul.yaml b/k8s/consul.yaml index 8b254adb..d8452a0c 100644 --- a/k8s/consul.yaml +++ b/k8s/consul.yaml @@ -2,8 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: consul - labels: - app: consul rules: - apiGroups: [""] resources: @@ -29,8 +27,6 @@ apiVersion: v1 kind: ServiceAccount metadata: name: consul - labels: - app: consul --- apiVersion: v1 kind: Service @@ -72,7 +68,7 @@ spec: terminationGracePeriodSeconds: 10 containers: - name: consul - image: "consul:1.5" + image: "consul:1.6" args: - "agent" - "-bootstrap-expect=3" diff --git a/k8s/persistent-consul.yaml b/k8s/persistent-consul.yaml index 64c35065..a08556bb 100644 --- a/k8s/persistent-consul.yaml +++ b/k8s/persistent-consul.yaml @@ -1,51 +1,54 @@ apiVersion: rbac.authorization.k8s.io/v1 -kind: Role +kind: ClusterRole metadata: - name: consul + name: persistentconsul rules: - - apiGroups: [ "" ] - resources: [ pods ] - verbs: [ get, list ] + - apiGroups: [""] + resources: + - pods + verbs: + - get + - list --- apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding +kind: ClusterRoleBinding metadata: - name: consul + name: persistentconsul roleRef: apiGroup: rbac.authorization.k8s.io - kind: Role - name: consul + kind: ClusterRole + name: persistentconsul subjects: - kind: ServiceAccount - name: consul - namespace: orange + name: persistentconsul + namespace: default --- apiVersion: v1 kind: ServiceAccount metadata: - name: consul + name: persistentconsul --- apiVersion: v1 kind: Service metadata: - name: consul + name: persistentconsul spec: ports: - port: 8500 name: http selector: - app: consul + app: persistentconsul --- apiVersion: apps/v1 kind: StatefulSet metadata: - name: consul + name: persistentconsul spec: - serviceName: consul + serviceName: persistentconsul replicas: 3 selector: matchLabels: - app: consul + app: persistentconsul volumeClaimTemplates: - metadata: name: data @@ -58,9 +61,9 @@ spec: template: metadata: labels: - app: consul + app: persistentconsul spec: - serviceAccountName: consul + serviceAccountName: persistentconsul affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -69,19 +72,19 @@ spec: - key: app operator: In values: - - consul + - persistentconsul topologyKey: kubernetes.io/hostname terminationGracePeriodSeconds: 10 containers: - name: consul - image: "consul:1.5" + image: "consul:1.6" volumeMounts: - name: data mountPath: /consul/data args: - "agent" - "-bootstrap-expect=3" - - "-retry-join=provider=k8s namespace=orange label_selector=\"app=consul\"" + - "-retry-join=provider=k8s label_selector=\"app=persistentconsul\"" - "-client=0.0.0.0" - "-data-dir=/consul/data" - "-server" diff --git a/slides/k8s/local-persistent-volumes.md b/slides/k8s/local-persistent-volumes.md index b2f86387..075cb619 100644 --- a/slides/k8s/local-persistent-volumes.md +++ b/slides/k8s/local-persistent-volumes.md @@ -56,28 +56,6 @@ --- -## Work in a separate namespace - -- To avoid conflicts with existing resources, let's create and use a new namespace - -.exercise[ - -- Create a new namespace: - ```bash - kubectl create namespace orange - ``` - -- Switch to that namespace: - ```bash - kns orange - ``` - -] - -.warning[Make sure to call that namespace `orange`: it is hardcoded in the YAML files.] - ---- - ## Deploying Consul - We will use a slightly different YAML file @@ -88,7 +66,9 @@ - the corresponding `volumeMounts` in the Pod spec - - the namespace `orange` used for discovery of Pods + - the label `consul` has been changed to `persistentconsul` +
+ (to avoid conflicts with the other Stateful Set) .exercise[ @@ -117,7 +97,7 @@ kubectl get pv ``` -- The Pod `consul-0` is not scheduled yet: +- The Pod `persistentconsul-0` is not scheduled yet: ```bash kubectl get pods -o wide ``` @@ -132,9 +112,9 @@ - In a Stateful Set, the Pods are started one by one -- `consul-1` won't be created until `consul-0` is running +- `persistentconsul-1` won't be created until `persistentconsul-0` is running -- `consul-0` has a dependency on an unbound Persistent Volume Claim +- `persistentconsul-0` has a dependency on an unbound Persistent Volume Claim - The scheduler won't schedule the Pod until the PVC is bound @@ -172,7 +152,7 @@ - Once a PVC is bound, its pod can start normally -- Once the pod `consul-0` has started, `consul-1` can be created, etc. +- Once the pod `persistentconsul-0` has started, `persistentconsul-1` can be created, etc. - Eventually, our Consul cluster is up, and backend by "persistent" volumes @@ -180,7 +160,7 @@ - Check that our Consul clusters has 3 members indeed: ```bash - kubectl exec consul-0 consul members + kubectl exec persistentconsul-0 consul members ``` ]