Context : Ionization plays a central role in the gas-phase chemistry of molecular clouds . Since ions are coupled with magnetic fields , which can in turn counteract gravitational collapse , it is of paramount importance to measure their abundance in star-forming regions . Aims : We use spectral line observations of the high-mass star-forming region NGC 6334 I to derive the abundance of two of the most abundant molecular ions , HCO ^ { + } and N _ { 2 } H ^ { + } , and consequently , the cosmic ray ionization rate . In addition , the line profiles provide information about the kinematics of this region . Methods : We present high-resolution spectral line observations conducted with the HIFI instrument on board the Herschel Space Observatory of the rotational transitions with J _ { up } \geq 5 of the molecular species C ^ { 17 } O , C ^ { 18 } O , HCO ^ { + } , H ^ { 13 } CO ^ { + } , and N _ { 2 } H ^ { + } . Results : The HCO ^ { + } and N _ { 2 } H ^ { + } line profiles display a redshifted asymmetry consistent with a region of expanding gas . We identify two emission components in the spectra , each with a different excitation , associated with the envelope of NGC 6334 I . The physical parameters obtained for the envelope are in agreement with previous models of the radial structure of NGC 6334 I based on submillimeter continuum observations . Based on our new Herschel /HIFI observations , combined with the predictions from a chemical model , we derive a cosmic ray ionization rate that is an order of magnitude higher than the canonical value of 10 ^ { -17 } s ^ { -1 } . Conclusions : We find evidence of an expansion of the envelope surrounding the hot core of NGC 6334 I , which is mainly driven by thermal pressure from the hot ionized gas in the region . The ionization rate seems to be dominated by cosmic rays originating from outside the source , although X-ray emission from the NGC 6334 I core could contribute to the ionization in the inner part of the envelope .