pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pyk8s
spec:
  containers:
  - name: py38
    image: registry.51nca.com:8950/python3:mysql.pika
    command: ["/bin/sh"] #保持循环
    args: ["-c", "while true; do echo hello; sleep 10;done"] 
    workingDir: /pydk
    volumeMounts: #k8s的master服务器对应的路径,必须存在
    - name: kube
      mountPath: /usr/bin/kubectl
    - name: admin
      mountPath: /root/.kube/config
    - name: pydk
      mountPath: /pydk
  restartPolicy: OnFailure
  volumes:
    - name: kube
      hostPath:
        path: /usr/bin/kubectl
    - name: admin
      hostPath:
        path: /etc/kubernetes/admin.conf
    - name: pydk
      hostPath:
        path: /root/pydk

api server配置

1.映射master的/etc/kubernetes/admin.conf至~/.kube/config
2.获取api server的地址
cat /etc/kubernetes/kubelet.conf | grep server
写入容器中hosts
echo "192.168.110.34    apiserver.cluster.local" >> /etc/hosts