• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. User Guide
  4. FAQs
  5. How to Use External Private Container Images By Means of kubectl?

How to Use External Private Container Images By Means of kubectl?

Prerequisites

Procedure

  1. Log in to a Linux server.
  2. Go to the directory where the kubectl binary file is stored.
  3. Run the following command to create a secret for the external private container registry:

    ./kubectl create secret docker-registry {secretname} --docker-server={registryserver} --docker-username={UserName} --docker-password={Password} --docker-email={emailaddress}

    Table 1 Parameters in the secret creation command

    Parameter

    Description

    secretname

    Name of the secret being created. Do not use the secret name myregistry because this name has been assigned to the default secret of CCE.

    registryserver

    Address of the external private container registry.

    UserName

    Username required for login to the external private container registry. If the username contains special characters, enclose them in a quotation mark.

    Password

    Password required for login to the external private container registry. If the password contains special characters, enclose them in a quotation mark.

    emailaddress

    Your email address.

  4. Run the following command to create an empty private-pod.yaml file (application configuration file):

    touch private-pod.yaml

  5. Edit the private-pod.yaml file.

    1. Run the following command to open the private-pod.yaml file:

      vi private-pod.yaml

    2. Press i to enter the file edit mode. Add the following configuration information to the file:
      apiVersion: v1
      kind: Pod
      metadata:
        name: pod-test
      spec:
        restartPolicy: Always
        containers:
        - name: nginx
          image: nginx:v1         
        imagePullSecrets:
        - name: registry                                                              

      In the configuration information:

      • nginx:v1 is an example name of the docker image.
      • registry is an example name of the secret created.
    3. Save the file and exit.

  6. Run the following command to create a containerized application using the private-pod.yaml file:

    ./kubectl create -f private-pod.yaml

  7. Run the following command to query status of the newly created application:

    ./kubectl get pods

    If the application is in the Running state, the container cluster has been successfully connected to the private container registry.