logs
1 2 3
| kubectl get pods kubectl logs podname -p kubectl logs podname
|
exec
1 2 3
| kubectl exec -it pod-name /bin/bash
cd /sys/fs/cgroup/memory
|
Constraint CPU & Memory
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
| apiVersion: apps/v1 kind: Deployment metadata: labels: app: myboot name: myboot spec: replicas: 1 selector: matchLabels: app: myboot template: metadata: labels: app: myboot spec: containers: - name: myboot image: 9stepsawesome/myboot:v1 ports: - containerPort: 8080 resources: requests: memory: "300Mi" cpu: "250m" limits: memory: "400Mi" cpu: "1000m"
|
ConfigMap
First Let’s see the environment.
Change the environment on deployment:
1
| kubectl set env deployment/myboot GREETING="hi"
|
Unset environment:
1
| kubectl set env deployment/myboot GREETING-
|
Then let’s see the config map.
kubectl create cm my-config --from-env-file=config/some.properties
some.properties:
1 2
| GREETING=LiuLixiang MSG=hello
|
deployment.yml which uses the ConfigMap:
1 2 3 4 5 6
| spec: containers: - name: myboot envFrom: - configMapRef: name: my-config
|
Partial.java
1 2 3 4
| @Autowired private Environment environment;
String greeting = environment.getProperties("GREETING", "default");
|
Secrets
1 2
| kubectl create secret generic mysecret --from-literal=user='username' --from-literal=password='mypassord' kubectl get secret mysecret -o yaml
|
Secrets’s data is encoded.
1
| echo 'dXNlcm5hbWU=' | base64 --decode
|
use the secret in the yaml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| spec: containers: - name: myboot image: 9stepsawesome/myboot:v1 ports: - containerPort: 8080 volumeMounts: - name: mysecretvolume mountPath: /mystuff/secretstuff readOnly: true volumes: - name: mysecretvolume secret: secretName: mysecret
|
use in the container:
1 2 3 4
| kubectl exec -it podname /bin/bash
cd /mystuff/secretstuff cat username
|