-
-
Save maurobaraldi/1fcfcfbb6bc907565f45bc10fccf9371 to your computer and use it in GitHub Desktop.
Revisions
-
ivanbrennan revised this gist
Dec 9, 2018 . 5 changed files with 106 additions and 78 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,5 @@ # create/update resources kubectl --context=minikube apply -f ./postgres.yaml # In order for the service to reach the statefulset, the following should # be true: @@ -15,14 +10,14 @@ kubectl --context=minikube create -f ./postgres-service.yaml # ... # test the connection from outside the cluster psql --host=$(minikube ip) \ --port=$(minikube service postgres --url --format={{.Port}}) \ --username=postgres \ --dbname=postgres # test the connection from within the cluster url=$(kubectl --context=minikube get service postgres \ --output=jsonpath='{.spec.clusterIP}:{.spec.ports[0].port}') kubectl --context=minikube run pgbox --image=postgres:9.6 \ --rm -it --restart=Never -- \ bash -c "read && @@ -31,6 +26,5 @@ kubectl --context=minikube run pgbox --image=postgres:9.6 \ --command='SELECT refobjid FROM pg_depend LIMIT 1'" # remove resources kubectl --context=minikube delete -f ./postgres.yaml --ignore-not-found # Data will survive the above operation, and be available next time you revive postgres. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,97 @@ apiVersion: v1 kind: PersistentVolume metadata: name: postgres spec: accessModes: - ReadWriteOnce capacity: storage: 2Gi hostPath: path: /data/postgres storageClassName: standard --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgres spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi volumeName: postgres --- apiVersion: v1 kind: Secret metadata: name: postgres type: Opaque data: POSTGRES_USER: cG9zdGdyZXM= # printf postgres | base64 POSTGRES_PASSWORD: cGFzc3dvcmQ= # printf password | base64 --- apiVersion: apps/v1beta2 kind: StatefulSet metadata: name: postgres labels: app: postgres role: service spec: replicas: 1 selector: matchLabels: app: postgres role: service serviceName: postgres template: metadata: labels: app: postgres role: service spec: containers: - name: postgres image: postgres:9.6 env: - name: POSTGRES_USER valueFrom: secretKeyRef: key: POSTGRES_USER name: postgres - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: key: POSTGRES_PASSWORD name: postgres ports: - containerPort: 5432 name: postgres protocol: TCP volumeMounts: - name: postgres mountPath: /var/lib/postgresql/data volumes: - name: postgres persistentVolumeClaim: claimName: postgres --- apiVersion: v1 kind: Service metadata: name: postgres labels: app: postgres role: service spec: selector: app: postgres role: service type: NodePort ports: - name: postgres port: 5432 targetPort: 5432 protocol: TCP -
ivanbrennan created this gist
Dec 8, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ # this setup doesn't include a persistent volume, just what's needed # to test connectivity from inside and outside the cluster. # create resources kubectl --context=minikube create -f ./postgres-secret.yaml kubectl --context=minikube create -f ./postgres-statefulset.yaml kubectl --context=minikube create -f ./postgres-service.yaml # In order for the service to reach the statefulset, the following should # be true: # statefulset.spec.selector.matchLabels.app == service.spec.selector.app # statefulset.spec.selector.matchLabels.role == service.spec.selector.role # give the server some time to start up # ... # test the connection from outside the cluster url=$(minikube service postgres --url \ --format={{.IP}}:{{.Port}}) psql --host=${url%:*} --port=${url#*:} --username=postgres --dbname=postgres \ --command='SELECT refobjid FROM pg_depend LIMIT 1' # test the connection from within the cluster url=$(kubectl --context=minikube get service postgres \ --output=jsonpath='{.spec.clusterIP}:{.spec.ports[0].port}') kubectl --context=minikube run pgbox --image=postgres:9.6 \ --rm -it --restart=Never -- \ bash -c "read && psql --host=${url%:*} --port=${url#*:} \ --username=postgres --dbname=postgres \ --command='SELECT refobjid FROM pg_depend LIMIT 1'" # remove resources kubectl --context=minikube delete service postgres kubectl --context=minikube delete statefulset postgres kubectl --context=minikube delete secret postgres This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ apiVersion: v1 kind: Secret metadata: name: postgres type: Opaque data: POSTGRES_USER: cG9zdGdyZXM= # printf postgres | base64 POSTGRES_PASSWORD: cGFzc3dvcmQ= # printf password | base64 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ apiVersion: v1 kind: Service metadata: name: postgres labels: app: postgres role: service spec: selector: app: postgres role: service type: NodePort ports: - name: postgres port: 5432 targetPort: 5432 protocol: TCP This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ apiVersion: apps/v1beta2 kind: StatefulSet metadata: name: postgres labels: app: postgres role: service spec: replicas: 1 selector: matchLabels: app: postgres role: service serviceName: postgres template: metadata: labels: app: postgres role: service spec: containers: - name: postgres image: postgres:9.6 env: - name: POSTGRES_USER valueFrom: secretKeyRef: key: POSTGRES_USER name: postgres - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: key: POSTGRES_PASSWORD name: postgres ports: - containerPort: 5432 name: postgres protocol: TCP