Oveview
Create your first configmap out of file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# ******************************* # create some dummy configuration # file first # ******************************* cat << EOF > app.properties driver=jdbc database=postgres lookandfeel=1 otherparams=xzy EOF # ******************************* # Create configmap with name: # - "app-config" # ******************************* cat app.properties kubectl create configmap app-config --from-file=app.properties kubectl get configmaps kubectl describe configmap app-config Name: app-config Namespace: default Labels: <none> Annotations: <none> Data ==== app.properties: ---- driver=jdbc database=postgres lookandfeel=1 otherparams=xzy Events: <none> |
Create nginx-config confimap object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# ********************************* # Our custom Nginx configuration # file # ********************************* cat reverseproxy.conf server { listen 80; server_name localhost; location / { proxy_bind 127.0.0.1; proxy_pass http://127.0.0.1:3000; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } # ********************************* # create nginx-config configmap # ********************************* kubectl create configmap nginx-config --from-file=reverseproxy.conf # ********************************* # show all available configmaps # ********************************* kubectl get configmaps NAME DATA AGE app-config 1 12m nginx-config 1 3m # ********************************* # describe "nginx-configmap" # ********************************* kubectl describe configmap nginx-config ... Data ==== reverseproxy.conf: ---- server { listen 80; server_name localhost; location / { proxy_bind 127.0.0.1; proxy_pass http://127.0.0.1:3000; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } Events: <none> ... |
Nginx service
1 2 3 4 5 6 7 8 9 10 11 |
apiVersion: v1 kind: Service metadata: name: helloworld-nginx-service spec: ports: - port: 80 protocol: TCP selector: app: helloworld-nginx type: NodePort |
Nginx pod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
apiVersion: v1 kind: Pod metadata: name: helloworld-nginx labels: app: helloworld-nginx spec: containers: - name: nginx image: nginx:1.11 ports: - containerPort: 80 volumeMounts: - name: config-volume mountPath: /etc/nginx/conf.d - name: k8s-demo image: wardviaene/k8s-demo ports: - containerPort: 3000 volumes: - name: config-volume configMap: name: nginx-config items: - key: reverseproxy.conf path: reverseproxy.conf |
In order to log in to particular container within pod there is some useful command below.
1 2 3 4 5 6 7 8 |
# **************************************************** # this pod "helloworld-nginx" has 2 containers inside # # helloworld-nginx - is a pod # -c nginx - is a container # **************************************************** kubectl exec -it helloworld-nginx -c nginx -- bash |