k8s学习
kubectl exec -it ds-test-m9mrh bash
进入到某个pod里面
kubectl exec -it ds-test-m9mrh bash
job.yaml
kubectl create -f .\job.yaml
apiVersion: batch/v1 kind: Job metadata: name: pi spec: template: spec: containers: - name: pi image: harbor.dcos.guangzhou.unicom.local/topia-zoo/perl:latest command: ["perl","-Mbignum=bpi","-wle","print bpi(2000)"] restartPolicy: Never backoffLimit: 4
kubectl logs pi-6fqxq
cronjob.yaml
apiVersion: batch/v1beta1 kind: CronJob metadata: name: hello spec: schedule: "*/1 * * * *" jobTemplate: spec: template: spec: containers: - name: hello image: harbor.dcos.guangzhou.unicom.local/common/busybox:test args: - /bin/sh - -c - date; echo Hello from the Kubernates cluster restartPolicy: OnFailure
secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
username: YWRtaW4=
password: MTIzNDU2
以变量形式挂载到容器中
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: nginx
image: harbor.dcos.guangzhou.unicom.local/common/nginx:latest
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: username
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: password
3.创建角色 rbac-role.yaml
kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: roledemo name: pod-reader rules: - apiGroups: [""] # "" indicate the core API group resources: ["pods"] verbs: ["get","watch","list"]